• 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!

GameMaker sleep function not working

S

Shadowblitz16

Guest
can someone help me with my sleep function?
basically its supposed to wait one second times the value you give it.
however it doesn't work.

Code:
/// @description sleep()
/// @param ms

var _s = argument[0]

var _time = room_speed * _s;
for(var t=0; t<_time; t++) { /*Idle*/ }
 
Last edited by a moderator:

kamiyasi

Member
In your example, there's no code in your for loop's brackets. Just a comment that says idle. Did you forget to add your sleep code?
 

Tthecreator

Your Creator!
This will just loop the for loop an x amount of time.

Using such a function in a game is NOT RECOMMENDED AT ALL. It will break stuff, and windows will even consider your program "frozen" and those "app not responding" errors will show up.

Anyways if you want to be stubborn:

Code:
var _s = argument0 //this is in microseconds (1 millionth of a second)
var _findtime=get_timer()+_s
while(findtime<get_timer()){}
Again, not recommended that you use this. Use separate timers and/or alarms to achieve what you want to.
 
S

Shadowblitz16

Guest
@kamiyasi the for loop is the sleep statement
@Tthecreator I need it to pause all execution of code not delay something. otherwise it breaks.

EDIT: ok so I came off a bit drastic there while loops do hang programs but it shouldn't as long as the sleep delay is not larger then the room speed.

I need it to halt code execution for n amount of frames. I will be careful where to use it. and how long I use it for.

what I'm doing is also called a synchronous timer which is fine as long as it's used properly.
 
Last edited by a moderator:

Tthecreator

Your Creator!
No it would be on your end.
Windows can detect if your program is stuck inside of a loop for a few seconds. It's 100% supposed to do that, and that's the way it's supposed and should work.
Also nothing about yoyo games end.
 

Tornado

Member
"Busy waiting" should be avoided.
On different processors (with different speeds) you will be getting different waiting times.
What exactly are you trying to achieve?
 
S

Shadowblitz16

Guest
I'm trying to make a ui element's wait to be deleted before executing it's update.
the wait and delete only happens if its state is not equal to the editors state.

also why can't I just sync it up with the room speed and fps?
 

Tthecreator

Your Creator!
You are completely misunderstanding how game maker processes things. Its very linear. GAME MAKER DOESN'T EXECUTE ANY CODE PARALLEL TO EACH OTHER, BUT EVERY LINE OF CODE 1 BY 1. this means that if object A has some code, and object B has some different code, that A's code will be executed before B's. If you take such a "sleep" command, it will prevent any other code in the game from running until that bit is over. Because game maker runs in a linear fashion, once all step codes are finished running, game maker goes over to the draw events and executes them one by one. Once that is finished it restarts at the step events again and handles them one by one.
 
Top