HomeForumsWhat's newResources 
 
 
Another C question...
Daniel Eriksson - Jan 15, 2002
   Daniel Eriksson Jan 15, 2002 
Is there a command in Saturn C that is similiar to SLEEP in basic. That stops the program until a button is pressed or the time goes out? Please help. I am making a game and i would need this!

   RadSil Jan 15, 2002 
Just do a while loop and check for a button press, and then break the loop when the button is pressed...

   Daniel Eriksson Jan 15, 2002 
Thanks, but how is the code to do that? I am very new to this. I am making a text adventure game and i would need a function like that.

   ExCyber Jan 15, 2002 
That won't do what he was asking for... I think what's needed is something like this (again, this isn't guaranteed to be correct):

Code:
  
void sleepuntilbutton (Uint32 frames) { while (frames > 0) { SlSynch(); if (Smpc_Peripheral[0].data && PER_DGT_TX) return; frames-- } }

This would (in theory) sleep for the specified number of frames, or until the X button is pressed. Of course, for a "real" program you'd probably want to abstract the button handling somehow...

edit: D'oh! Forgot the closing code tag...

(Edited by ExCyber at 4:21 pm on Jan. 15, 2002)

   Daniel Eriksson Jan 15, 2002 
Thanks again! I´ll try it.

   RadSil Jan 16, 2002 
Oops. Didn't notice the "until time goes out"... I could have been more specific anyway