• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Global var equals same global var

  • Thread starter Deleted member 16767
  • Start date
D

Deleted member 16767

Guest
Why can this not be done? I am trying to make moving layers work smoothly in my layer inspector. I am making a painting software. No one will read the layer system code if I put it here (too long) so I am just asking the question I have in the title.

For example:

s4 is number 4 in global.final_surf.
s5 is number 5 in global.final_surf.

s4 can get moved to s5 (and other layers) but not move back to s4.
s5 cant get moved to s5 either.
 
D

Deleted member 16767

Guest
I don't think surfaces are in arrays. I am just trying to move one surface to the spot it originally was on when the program starts. So s4 is global.final_surf = 4. Global.final_surf is the main surface I use for my painting canvas.

What boggles me is that the layers can't move back to where they started at. So I need to move it one layer above where it originally started, and because it can't move they can't move to their original spots they move one spot below or above.

GML:
if s4 = global.final_surf && mouse_check_button_pressed(mb_right)
{
    
            if global.layershow = 1
        {
        if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s4
    

    global.final_surf = s4


    
}
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s4
    

    global.final_surf = s4


    
}
And this code is a lot longer than you think it is.
 

NightFrost

Member
Okay so s4, s5 (and presumably s1, s2, s3, s6 etc) are variables where you are storing references from surface_create calls? And global.final_surf will refer to the surface you are actively working on / displaying?
 
D

Deleted member 16767

Guest
s4, s5, s6, s7 and so on are just numbers. The numbers are stored in global.final_surf. Which is stored in surface_create.
 

NightFrost

Member
Ah, so you're using them as ordering aid to inform the code about the surfaces' current stacking order. It might actually be simpler to directly store the surfaces into an array or a ds_list, where their storage order is considered as their stacking order. So when you want to move a surface/layer to another height, you remove it from original position and insert it at new position in the array or list. And when you want to go through them all, you for-loop across it from zero up to its length minus one. (Or vice versa if you want to go from top to bottom.)
 
D

Deleted member 16767

Guest
I've tried making surfaces inside an array but I get an error. This was on GMS2.3 but not the latest patch. Are you sure that you can put surfaces in array?
 

NightFrost

Member
Are you sure that you can put surfaces in array?
Yes. The surface create returns an ID reference to the surface, so it is something you can put in an array. Or for example ds_list if you prefer using those. A very basic example would be something like:
GML:
Layers = array_create(5);
Layers[0] = surface_create(200, 200);
Layers[1] = surface_create(200, 200);
Layers[2] = surface_create(200, 200);
Layers[3] = surface_create(200, 200);
Layers[4] = surface_create(200, 200);
Which would store references to five 200*200 surfaces to array.
 

gnysek

Member
Remember, that surfaces can be deleted at any time by GPU, so keeping important data on them and not having a way to redraw it from scratch will at some point break your game (PC sleep/hibernate, screensaver, hanging/locking session).
Also, as there's no way to draw two surfaces at same time (only in same frame), I think, that having only one should be enough.
Generally, using GMS to create painting tool leads to bugs.
 
D

Deleted member 16767

Guest
I didn't plan to have several surfaces on at the same time. I don't have 100 people working on it that could make million of code text just because of several different surfaces.

Nah, I've tested my painting software very often for a year and a half now and the surfaces has not disappeared. Sitting at 1k+ fps while drawing.
 

Nidoking

Member
I see this line in your code. I think this means that you don't really understand how variables work. It seems like you want s4, s5, etc. to retain their original values, but you also want to change what those values are as the program runs. That isn't how it works. If you assign a new value to s4, then the previous value of s4 is no longer associated with the variable s4. The value formerly stored in s4 can no longer be referred to as s4, because you overwrote it. What you probably wanted to do was use one set of variables to store the original values, and a second set of variables to store the actual current order in use. Never change the first set. I repeat, never change the first set.
 
D

Deleted member 16767

Guest
I think i tried that if I understand what you mean, and it does not work. Well, this is not really a big issue since the user can merge images in an orderless system anyway. But it is concerning me a bit since some users may actually refund just because they need to order them the right way. Maybe it looks ugly to them idk.
 

Mr Magnus

Viking King

s4 = s4


what exactly is this supposed to do? This is a redundant line, it does nothing. s4 is already equal to s4 by definition.
 
D

Deleted member 16767

Guest
Well, I was wanting s5 = s4, then s4 = s4. But I guess it can't work like this due to how coding works. I've tried new variables with numbers, didn't work either. I think it has to do with global.final_surf = number. But I'm not sure.
 

kburkhart84

Firehammer Games
So what is the s4=s4 supposed to be doing exactly? If you tell us the sequence of events you are wanting to happen in those couple of lines of code, we can likely tell you how to do it. But doing s5 = s4, then s4 = s4, is going to simply make s5 be whatever s4 is, and s4 won't change since you are just making it equal to itself.

But it is concerning me a bit since some users may actually refund just because they need to order them the right way. Maybe it looks ugly to them idk.
Since it is a painting program, and you are interested in making the users happy, you can go ahead and code what they need. If they need to order layers the right way, code that in. Someone above suggested using arrays or lists for that, it can certainly help. There is nothing stopping you from keeping multiple surface references in arrays in order to have layers like that. I'm hoping you also understand that surfaces as you access them are simply references, just numbers. In fact, most things in GM ARE just numbers as far as our GML is concerned, it is under the hood that the code accesses the resource based on that. If the feature is important to you, I'd recommend you go ahead and code it, and if you can't figure out how to make it work with arrays, feel free to post asking for help on it(as long as you have some code to show what you are trying to do and can explain it as well).
 
D

Deleted member 16767

Guest
But... s4 is already s4. What is the change you are seeking as a result of running s4 = s4? What is the intent? What purpose is it supposed to fulfill?
It is for a visual layer interface. You move the visual layer up or down with RMB press. It doesn't really have any purpose but to make it look slicker I guess.
 

kburkhart84

Firehammer Games
It is for a visual layer interface. You move the visual layer up or down with RMB press. It doesn't really have any purpose but to make it look slicker I guess.
So how are you storing that visual order? How do you know at any point in time what layer is where in the stack?
 
D

Deleted member 16767

Guest
GML:
s4 = 4
s5 = 5
s6 = 6
s7 = 7
s8 = 8
s9 = 9
s10 = 10
s11 = 11
s12 = 12
s13 = 13
GML:
    if s4 = s5
    {

    s4 = 5
    

    }




    if s4 = s6
    {

    s4 = 6

    }

    if s4 = s7
    {

    s4 = 7

    }

    if s4 = s8
    {

    s4 = 8

    }

    if s4 = s9
    {

    s4 = 9

    }

    if s4 = s10
    {

    s4 = 10

    }
    
        if s4 = s11
    {

    s4 = 11

    }
    
        if s4 = s12
    {

    s4 = 12

    }

        if s4 = s13
    {

    s4 = 13

    }




    if s5 = s4
    {

    s5 = 4
    }





    if s5 = s6
    {

    s5 = 6

    }

    if s5 = s7
    {

    s5 = 7

    }

    if s5 = s8
    {

    s5 = 8

    }


    if s5 = s9
    {

    s5 = 9

    }

    if s5 = s10
    {

    s5 = 10

    }
    
        if s5 = s11
    {

    s5 = 11

    }
    
        if s5 = s12
    {

    s5 = 12

    }

        if s5 = s13
    {

    s5 = 13

    }







    if s6 = s4
    {

    s6 = 4
    }


    if s6 = s5
    {

    s6 = 5
    }





    if s6 = s7
    {

    s6 = 7

    }

    if s6 = s8
    {

    s6 = 8

    }


    if s6 = s9
    {

    s6 = 9

    }

    if s6 = s10
    {

    s6 = 10

    }
    
        if s6 = s11
    {

    s6 = 11

    }
    
        if s6 = s12
    {

    s6 = 12

    }

        if s6 = s13
    {

    s6 = 13

    }


    
    
    
    if s7 = s4
    {

    s7 = 4
    }


    if s7 = s5
    {

    s7 = 5
    }


    if s7 = s6
    {

    s7 = 6

    }






    if s7 = s8
    {

    s7 = 8

    }

    if s7 = s9
    {

    s7 = 9

    }

    if s7 = s10
    {

    s7 = 10

    }
    
        if s7 = s11
    {

    s7 = 11

    }
    
        if s7 = s12
    {

    s7 = 12

    }

        if s7 = s13
    {

    s7 = 13

    }



    if s8 = s4
    {

    s8 = 4
    


    }


    if s8 = s5
    {

    s8 = 5
    
    
    }


    if s8 = s6
    {

    s8 = 6


    }

    if s8 = s7
    {

    s8 = 7

    }
    

    

    if s8 = s9
    {

    s8 = 9

    }

    if s8 = s10
    {

    s8 = 10

    }
    
        if s8 = s11
    {

    s8 = 11

    }
    
        if s8 = s12
    {

    s8 = 12

    }

        if s8 = s13
    {

    s8 = 13

    }
    
    
    if s9 = s4
    {

    s9 = 4
    


    }


    if s9 = s5
    {

    s9 = 5
    
    
    }


    if s9 = s6
    {

    s9 = 6


    }

    if s9 = s7
    {

    s9 = 7

    }

    if s9 = s8
    {

    s9 = 8

    }
    


    if s9 = s10
    {

    s9 = 10

    }
    
        if s9 = s11
    {

    s9 = 11

    }
    
        if s9 = s12
    {

    s9 = 12

    }

        if s9 = s13
    {

    s9 = 13

    }


if s10 = s4
    {

    s10 = 4
    


    }


    if s10 = s5
    {

    s10 = 5
    
    
    }


    if s10 = s6
    {

    s10 = 6


    }

    if s10 = s7
    {

    s10 = 7

    }

    if s10 = s8
    {

    s10 = 8

    }

    if s10 = s9
    {

    s10 = 9

    }
    


    
        if s10 = s11
    {

    s10 = 11

    }
    
        if s10 = s12
    {

    s10 = 12

    }

        if s10 = s13
    {

    s10 = 13

    }



if s11 = s4
    {

    s11 = 4
    


    }


    if s11 = s5
    {

    s11 = 5
    
    
    }


    if s11 = s6
    {

    s11 = 6


    }

    if s11 = s7
    {

    s11 = 7

    }

    if s11 = s8
    {

    s11 = 8

    }

    if s11 = s9
    {

    s11 = 9

    }
    
        if s11 = s10
    {

    s11 = 10

    }
    


    
        if s11 = s12
    {

    s11 = 12

    }

        if s11 = s13
    {

    s11 = 13

    }



if s12 = s4
    {

    s12 = 4
    


    }


    if s12 = s5
    {

    s12 = 5
    
    
    }


    if s12 = s6
    {

    s12 = 6


    }

    if s12 = s7
    {

    s12 = 7

    }

    if s12 = s8
    {

    s12 = 8

    }

    if s12 = s9
    {

    s12 = 9

    }
    
        if s12 = s10
    {

    s12 = 10

    }
    
        if s12 = s11
    {

    s12 = 11

    }
    


        if s12 = s13
    {

    s12 = 13

    }



if s13 = s4
    {

    s13 = 4
    


    }


    if s13 = s5
    {

    s13 = 5
    
    
    }


    if s13 = s6
    {

    s13 = 6


    }

    if s13 = s7
    {

    s13 = 7

    }

    if s13 = s8
    {

    s13 = 8

    }

    if s13 = s9
    {

    s13 = 9

    }
    
        if s13 = s10
    {

    s13 = 10

    }
    
        if s13 = s11
    {

    s13 = 11

    }

        if s13 = s12
    {

    s13 = 12

    }
GML:
if s4 = global.final_surf && mouse_check_button_pressed(mb_right)
{
    
            if global.layershow = 1
        {
        if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s4
    

    global.final_surf = s4


    
}
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s4
    

    global.final_surf = s4


    
}

        }
        
        
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s6 = s4
    

    global.final_surf = s4



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s7 = s4
    

    global.final_surf = s4


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s4
    

    global.final_surf = s4

}

        
        
        
                if global.layershow = 2
        {
    
        if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s4
    

    global.final_surf = s4

    
}
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s4
    

    global.final_surf = s4


    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s11 = s4
    

    global.final_surf = s4


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s4
    

    global.final_surf = s4



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s4
    

    global.final_surf = s4

}

        }
}



if s5 = global.final_surf && mouse_check_button_pressed(mb_right)
{
            if global.layershow = 1
        {
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s5
    

    global.final_surf = s5

}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s5
    

    global.final_surf = s5


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s6 = s5
    

    global.final_surf = s5


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{


    s7 = s5
    

    global.final_surf = s5


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s5
    

    global.final_surf = s5


}
        }
        
                if global.layershow = 2
        {

            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s5
    

    global.final_surf = s5

}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s5
    

    global.final_surf = s5


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s11 = s5
    



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s5
    

    global.final_surf = s5


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s5
    

    global.final_surf = s5

}


}

}

if s6 = global.final_surf && mouse_check_button_pressed(mb_right)
{
        if global.layershow = 1
        {   
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s6
    

    global.final_surf = s6


}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s6
    

    global.final_surf = s6


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{


    s6 = s6
    

    global.final_surf = s6


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s7 = s6
    

    global.final_surf = s6


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s6
    

    global.final_surf = s6


}

        }
        
                if global.layershow = 2
        {
    
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s6
    

    global.final_surf = s6


}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s6
    

    global.final_surf = s6


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s11 = s6
    

    global.final_surf = s6


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s6
    

    global.final_surf = s6

}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s6
    

    global.final_surf = s6


}

}


}

if s7 = global.final_surf && mouse_check_button_pressed(mb_right)
{
            if global.layershow = 1
        {
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s7
    

    global.final_surf = s7
    

    
}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s7
    

    global.final_surf = s7

    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s6 = s7
    

    global.final_surf = s7
    


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s7 = s7
    

    global.final_surf = s7

}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s7
    

    global.final_surf = s7


}
        }
        
                if global.layershow = 2
        {

            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s7
    

    global.final_surf = s7


    
}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s7
    

    global.final_surf = s7
    

    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{
    
    s11 = s7
    

    global.final_surf = s7



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s7
    

    global.final_surf = s7

}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s7
    

    global.final_surf = s7


}

}
}






if s8 = global.final_surf && mouse_check_button_pressed(mb_right)
{
        if global.layershow = 1
        {   
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s8
    

    global.final_surf = s8

}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s8
    

    global.final_surf = s8
    

    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s6 = s8
    

    global.final_surf = s8


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s7 = s8
    


    global.final_surf = s8



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s8
    


    global.final_surf = s8



}

        }
        
                if global.layershow = 2
        {

            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s8
    

    global.final_surf = s8

    
}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s8
    

    global.final_surf = s8

    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s11 = s8
    

    global.final_surf = s8



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s8
    


    global.final_surf = s8


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s8
    


    global.final_surf = s8


}

}
}

if s9 = global.final_surf && mouse_check_button_pressed(mb_right)
{
        if global.layershow = 1
        {   
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s9
    

    global.final_surf = s9

    
}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s9
    

    global.final_surf = s9
    

    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s6 = s9
    

    global.final_surf = s9



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s7 = s9
    


    global.final_surf = s9



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s9
    


    global.final_surf = s9



}

        }
        
        
                if global.layershow = 2
        {

            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s9
    

    global.final_surf = s9


}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s9
    

    global.final_surf = s9


    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s11 = s9
    

    global.final_surf = s9



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s9
    


    global.final_surf = s9



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s9
    


    global.final_surf = s9


}

}
}


if s10 = global.final_surf && mouse_check_button_pressed(mb_right)
{
            if global.layershow = 1
        {
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s10
    

    global.final_surf = s10


}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s10
    

    global.final_surf = s10


    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s6 = s10
    

    global.final_surf = s10


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s7 = s10
    


    global.final_surf = s10



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s10
    


    global.final_surf = s10



}
        }
        
                if global.layershow = 2
        {


            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s10
    

    global.final_surf = s10

    
}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s10
    

    global.final_surf = s10


    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s11 = s10
    

    global.final_surf = s10



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s10
    


    global.final_surf = s10


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s10
    


    global.final_surf = s10


}

}
}

if s11 = global.final_surf && mouse_check_button_pressed(mb_right)
{
            if global.layershow = 1
        {
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s11
    

    global.final_surf = s11

}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s11
    

    global.final_surf = s11


    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s6 = s11
    

    global.final_surf = s11



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s7 = s11
    


    global.final_surf = s11


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s11
    


    global.final_surf = s11


}

        }
                if global.layershow = 2
        {

            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s11
    

    global.final_surf = s11

    
}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s11
    

    global.final_surf = s11
    

    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s11 = s11
    

    global.final_surf = s11



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s11
    


    global.final_surf = s11



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s11
    


    global.final_surf = s11



}

}
}



if s12 = global.final_surf && mouse_check_button_pressed(mb_right)
{
            if global.layershow = 1
        {
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s12
    

    global.final_surf = s12

    
}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s12
    

    global.final_surf = s12
    

    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s6 = s12
    

    global.final_surf = s12



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s7 = s12
    


    global.final_surf = s12



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s12
    


    global.final_surf = s12



}
        }

        if global.layershow = 2
        {
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s12
    

    global.final_surf = s12


}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s12
    

    global.final_surf = s12


    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s11 = s12
    

    global.final_surf = s12



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s12
    


    global.final_surf = s12


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s12
    


    global.final_surf = s12



}

}

}


if s13 = global.final_surf && mouse_check_button_pressed(mb_right)
{
            if global.layershow = 1
        {
            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s4 = s13
    

    global.final_surf = s13

}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s5 = s13
    

    global.final_surf = s13
    

    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s6 = s13
    

    global.final_surf = s13



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s7 = s13
    


    global.final_surf = s13



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s8 = s13
    


    global.final_surf = s13


}
        }
        if global.layershow = 2
        {

            if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,880,200+1700,200+880)

{

    s9 = s13
    

    global.final_surf = s13

}
    
    
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,660,200+1700,200+660)

{

    s10 = s13
    

    global.final_surf = s13


    
}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,440,200+1700,200+440)
{

    s11 = s13
    

    global.final_surf = s13


}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,220,200+1700,200+220)
{

    s12 = s13
    


    global.final_surf = s13



}

    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),
1700,0,200+1700,200+0)
{

    s13 = s13
    


    global.final_surf = s13



}

}
 

kburkhart84

Firehammer Games
I see multiple problems here.

1. You are setting s4 etc... to numbers...but yet you are comparing that to the value of a surface. You should not be doing that at all. Surface references are just references...yes they are numbers but you should not be using them like numbers. So you shouldn't be comparing them to numbers.

2....s4 = 4; s5 = 5; followed by if s4 = s5{s4 = 5} later in the code also seems wrong. If s4 is equal to s5(which should be 5), you then proceed to set s4 to 5(directly). Why are you setting the variable to what it already is?

3)global.final_surf = s4 Is there a surface reference stored in s4 at this point? I think you mentioned above that your surface reference was only stored in global.final_surf. If you, every time you run this line of code you are losing that surface reference and would need to recreate it.

The gist of this...it seems like you are treating your s4...s10... all those variables as if you have multiple of said variables. But there is nothing to indicate you actually do. This is why s4 = s4; does literally nothing, because you are setting the variable to the same thing it already is.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Is this if sX == sOtherX { sX = magicNumber } repeated a thousand times actual code from your project? If so, you don't need a hundred people to write millions of lines of code in the least efficient way possible, you need single person who implements features properly. I seriously hope you used some sort of automated code generation to write that because I'd feel sorry for your fingers otherwise.

However it was made, it's not remotely the proper way to do whatever you're trying to do, and from the look of it, the problems you are facing now are the long-term results of this fundamental lack of proper planning and execution. If I understood this correctly, you're trying to implement a way for layers in drawing software to be rearrangeable? If so, you don't implement that via a bunch of numbered variables and setting them to magic numbers and then duplicate that code by the maximum amount of layers, you implement that via a list and removing and inserting elements and make it work for any amount of layers without code duplication.
 
Are you familiar to how variables work? Not trying to be mean, but by looking at your code, it seems like you're trying to use each variable as if they're slots of an array or list, wich was also already suggested to you.
Then it seems like your'e trying to check if a surface is inside one of those slots, but please, tell us in wich EVENT are you putting your code inside? If you set: s4 = 4; s5 = 5; in create event but then compare the two inside step event without changing these values, it would be like asking "is 4 equal to 5?". This condition will always return false, an will execute no code after.
 

TailBit

Member
Took a look over it, it had a wrongly placed } and also formated it differently so I would be able to read it:
GML:
if s4 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s4; global.final_surf = s4; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s4; global.final_surf = s4; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s4; global.final_surf = s4; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s4; global.final_surf = s4; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s4; global.final_surf = s4; }
    } // this was at wrong place
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s4; global.final_surf = s4; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s4; global.final_surf = s4; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s4; global.final_surf = s4; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s4; global.final_surf = s4; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s4; global.final_surf = s4; }
    }
}
if s5 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s5; global.final_surf = s5; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s5; global.final_surf = s5; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s5; global.final_surf = s5; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s5; global.final_surf = s5; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s5; global.final_surf = s5; }
    }
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s5; global.final_surf = s5; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s5; global.final_surf = s5; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s5; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s5; global.final_surf = s5; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s5; global.final_surf = s5; }
    }
}
if s6 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s6; global.final_surf = s6; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s6; global.final_surf = s6; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s6; global.final_surf = s6; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s6; global.final_surf = s6; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s6; global.final_surf = s6; }
    }
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s6; global.final_surf = s6; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s6; global.final_surf = s6; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s6; global.final_surf = s6; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s6; global.final_surf = s6; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s6; global.final_surf = s6; }
    }
}
if s7 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s7; global.final_surf = s7; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s7; global.final_surf = s7; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s7; global.final_surf = s7; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s7; global.final_surf = s7; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s7; global.final_surf = s7; }
    }
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s7; global.final_surf = s7; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s7; global.final_surf = s7; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s7; global.final_surf = s7; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s7; global.final_surf = s7; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s7; global.final_surf = s7; }
    }
}
if s8 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s8; global.final_surf = s8; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s8; global.final_surf = s8; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s8; global.final_surf = s8; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s8; global.final_surf = s8; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s8; global.final_surf = s8; }
    }
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s8; global.final_surf = s8; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s8; global.final_surf = s8; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s8; global.final_surf = s8; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s8; global.final_surf = s8; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s8; global.final_surf = s8; }
    }
}
if s9 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s9; global.final_surf = s9; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s9; global.final_surf = s9; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s9; global.final_surf = s9; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s9; global.final_surf = s9; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s9; global.final_surf = s9; }
    }
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s9; global.final_surf = s9; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s9; global.final_surf = s9; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s9; global.final_surf = s9; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s9; global.final_surf = s9; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s9; global.final_surf = s9; }
    }
}
if s10 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s10; global.final_surf = s10; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s10; global.final_surf = s10; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s10; global.final_surf = s10; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s10; global.final_surf = s10; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s10; global.final_surf = s10; }
    }
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s10; global.final_surf = s10; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s10; global.final_surf = s10; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s10; global.final_surf = s10; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s10; global.final_surf = s10; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s10; global.final_surf = s10; }
    }
}
if s11 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s11; global.final_surf = s11; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s11; global.final_surf = s11; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s11; global.final_surf = s11; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s11; global.final_surf = s11; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s11; global.final_surf = s11; }
    }
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s11; global.final_surf = s11; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s11; global.final_surf = s11; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s11; global.final_surf = s11; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s11; global.final_surf = s11; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s11; global.final_surf = s11; }
    }
}
if s12 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s12; global.final_surf = s12; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s12; global.final_surf = s12; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s12; global.final_surf = s12; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s12; global.final_surf = s12; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s12; global.final_surf = s12; }
    }
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s12; global.final_surf = s12; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s12; global.final_surf = s12; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s12; global.final_surf = s12; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s12; global.final_surf = s12; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s12; global.final_surf = s12; }
    }
}
if s13 = global.final_surf && mouse_check_button_pressed(mb_right) {
    if global.layershow = 1 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s4 = s13; global.final_surf = s13; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s5 = s13; global.final_surf = s13; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s6 = s13; global.final_surf = s13; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s7 = s13; global.final_surf = s13; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s8 = s13; global.final_surf = s13; }
    }
    if global.layershow = 2 {
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 880, 200 + 1700, 200 + 880) { s9 = s13; global.final_surf = s13; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 660, 200 + 1700, 200 + 660) { s10 = s13; global.final_surf = s13; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 440, 200 + 1700, 200 + 440) { s11 = s13; global.final_surf = s13; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 220, 200 + 1700, 200 + 220) { s12 = s13; global.final_surf = s13; }
        if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700,   0, 200 + 1700, 200 +   0) { s13 = s13; global.final_surf = s13; }
    }
}
now .. if all those s0 to s13 were arrays going from s[0] to s[13], then it would be possible to write all that as:

GML:
if mouse_check_button_pressed(mb_right)
if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 1700, 0, 200 + 1700, 200 + 880){

    // getting the number by dividing y with 220 .. adding 5 if on layer 2
    // the "8 -" because 8 is at top and then it counts down, so this could be cleaner
    var pos = 8 - (device_mouse_y_to_gui(0) div 220) + (global.layershow-1) * 5;
  
    // swap values, that's what you are trying to do?
    var temp             = s[global.final_surf];
    s[global.final_surf] = s[pos];
    s[pos]               = temp;

    global.final_surf    = pos;
}
arrays and lists are your friend ^^
 
Last edited:
D

Deleted member 16767

Guest
@TsukaYuriko No need to feel sorry for my fingers. Making a painting software, especially with layers, is a lot of copy and pasting and changing the name of the image. That is why I told my users that I have finished the software and will work on bugs but that I might make expansions (not clarifying what kind of expansion, which I won't here either but you can take a wild guess already I guess).

@TailBit Thanks for shortening the code. I will be using that in case I expand on it more in the future. Thanks for pointing out where I missed the } also. So I put back s4 = 4, s5 = 5 in the code above that I showed you all and now the rearranging is working. Layer 1 moved to Layer 2 can move bac to Layer 1 and so on and so forth.
 
Top