You can't use a loop. Loops will repeat within the same frame and no other code will be run until it is done. So you would want to use a timer for this. You might actually want or need to use both a timer and state machine. Your code is simple enough that a single variable would be enough. I reworked the code to have a properly set up timer, and I think this is what you were going for, though giving how fast you allow movement in the other direction, you probably don't actually want a delay of 1 second (assuming roomspeed is 60) for up and down.
GML:
//changed this section
if (keyboard_check(ord("W"))) {
//if holding W, count down
step_delay -= 1;
//this portion will 'fire' when the alarm reaches 0 or less
if (step_delay <= 0)
{
//reset timer
step_delay = 60;
//move up or down based on current 'state'
if (move_up)
{
y += 2;
}
else
{
y -= 1;
}
//flip state so it will be the opposite next time
move_up = !move_up;
}
}
else
{
//keep the timer at the default if W is not pressed
step_delay = 60;
}
//unchanged
if (keyboard_check(ord("A"))) {
x-=1
}
//unchanged
if (keyboard_check(ord("S"))) {
y+=1
}
//unchanged
if (keyboard_check(ord("D"))) {
x+=1
}
Hi, I tried running your script, I tweaked it a bit and tried several versions but it wouldn't work. I got this error:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object RolkoietCalmWater:
Variable RolkoietCalmWater.move_up(100003, -2147483648) not set before reading it.
at gml_Object_RolkoietCalmWater_Step_0 (line 11) - if (move_up)
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_RolkoietCalmWater_Step_0 (line 11)
Then I tried making a variable but then it wouldn't run at all. I don't need it to be opposite though, the idea is that it's a current in a river and although you move upwards, you don't make any progress.
Do you have any ideas on what the problem might be?