P
paulog
Guest
Hello! I'm making a game in GM1.4 but I'm facing some issues. I really hope somene can help me out.
In the game some objects have to jump to another position if the player clicks a button.
I made two variables, "global.rot" and "global.oldrot". They both have the value of 1 when the room starts, and cycle between 1 and 4.
When the button is clicked the value of "global.rot" is increased by 1 in the button object.
In the moving object, the step event tests if "global.rot" is different than "global.oldrot". If it is, the object jumps 100 pixels and "global.oldrot" get the same value as "global.rot".
The code is like this:
This works, but only for one instance of the object in the room. I don't understand how this can be. I tried to change the instance ordering but that does not seem to have any effect. The code only works for the first instance of the moving object that I place in the room. If I delete all the instances and place just one, it will work for this one, but if I place more, it will still only work for that first one.
I did draw both variables "global.rot" and "global.oldrot" on the screen and they are changing from 1 to 4, so that part seems to be working fine.
I'd like to know what I'm doing wrong and if there is a way to fix this, either by changing the code or by having a different approach.
Thanks in advance
In the game some objects have to jump to another position if the player clicks a button.
I made two variables, "global.rot" and "global.oldrot". They both have the value of 1 when the room starts, and cycle between 1 and 4.
When the button is clicked the value of "global.rot" is increased by 1 in the button object.
In the moving object, the step event tests if "global.rot" is different than "global.oldrot". If it is, the object jumps 100 pixels and "global.oldrot" get the same value as "global.rot".
The code is like this:
GML:
if global.rot = 1
{
if global.rot != global.oldrot
{
x+=50
global.oldrot = global.rot
}
}
if global.rot = 2
{
if global.rot != global.oldrot
{
x+=100
global.oldrot = global.rot
}
}
if global.rot = 3
{
if global.rot != global.oldrot
{
x+=150
global.oldrot = global.rot
}
}
if global.rot = 4
{
if global.rot != global.oldrot
{
x+=200
global.oldrot = global.rot
}
}
I did draw both variables "global.rot" and "global.oldrot" on the screen and they are changing from 1 to 4, so that part seems to be working fine.
I'd like to know what I'm doing wrong and if there is a way to fix this, either by changing the code or by having a different approach.
Thanks in advance