Loops before previous code line?

A

Adam Bissmarck

Guest
The following code does the counting loop before doing room_goto(black_screen). How come? I have tried the same with while statement, but with the same result.

if (place_meeting(x,y,odevil))
{
counter=1;
room_goto(black_screen);
{
do
{
counter++;
}
until counter=30000000;
}
}

Also, if there are better ways to implement a waiting time for the player, I'm intererested to learn about that!

Thanks! / Adam
 

CloseRange

Member
that's always how it is. room_goto or saying room = will just create a callback.
here is a quote from the room_goto docs
Note that the room will not change until the end of the event where the function was called, so any code after this has been called will still run.
so what ya want to do is set a variable that tells the next frame of logic that it needs to run the code.
You could also try setting a 1 frame alarm and putting it in there, that might work as well.
 

Bentley

Member
Don't use a loop to get the wait. A loop finishes before any other code runs.

// This will crash your game b/c the loop can't terminate
count = 0;
while (count != 5)
{
count += 2; // 2, 4, 6, will never equal 5 so the loop will never stop
}

Try using an alarm
 
Last edited:
T

TinyGamesLab

Guest
Alarm[0] = 30000000;

And then on the alarm code use the room_goto(black_screen)
 
Alarm[0] = 30000000;
This will have a slightly different effect than the original code. Alarms are updated once per Step. At a room speed of 60, an alarm with the value of 30 million will take almost 6 days to trigger! :)

the original code has the computer counting from 0 to 30000000 in one Step, so this will be purely dependent on the clock speed, I think 30 million cycles would take a few seconds to count.
 
T

TinyGamesLab

Guest
This will have a slightly different effect than the original code. Alarms are updated once per Step. At a room speed of 60, an alarm with the value of 30 million will take almost 6 days to trigger! :)

the original code has the computer counting from 0 to 30000000 in one Step, so this will be purely dependent on the clock speed, I think 30 million cycles would take a few seconds to count.
You are correct! When posting I though
"What a large number, it looks like it will take some time to run it" but I didn't make the calculations myself.
Best bet would be to set the alarm to something int the range of 90 - 150 steps.
 
A

Adam Bissmarck

Guest
HI, thanks for all input to this question! I'll look into the alarm solution.

BR / Adam
 
Top