Suggestion: WaitUntil....

Started by Alynn, Wed 23/06/2004 12:58:16

Previous topic - Next topic

Alynn

Maybe I missed this, but since it's been 2.5 months I've been AGSless because of being in Iraq, here is something that I could use in my game, and I'm sure it could be used on others...

WaitUntilMousePressed(int MouseButton);
WaitUntilKeyPressed(int KeyNumber);

It should be obvious, but these functions will block the game until the appropriate mouse button is pressed, or the correct key is pressed. This would be great for pausing the game (which I have coded in with the on_keypress function, but this could be a much easier way to do it), as well as when you read a note right now I have it setup with a graphic overlay with a 10 minute wait for a mouse, click to remove it...
This way instead of setting it up that way I could just have the game wait until the player clicks the mouse to remove the overlay.

In my mind (however empty it may be), it should be fairly easy to implement... but then again, I don't know the source ;)

Scorpiorus

Those two should do the trick:

function WaitUntilMousePressed(int MouseButton) {

   while (IsButtonDown(MouseButton)==0) Wait(1);
}


function WaitUntilKeyPressed(int KeyNumber) {

   while (IsKeyPressed(KeyNumber)==0) Wait(1);
}

Pumaman

And of course, there's  WaitKey  ;)

Alynn

WaitKey doesn't wait indefinately... Unless you set it for some ungodly high number (like I said I have it set for 24000 right now for the graphic overlay to make sure the player has enough time to read the thing espeically for the slow readers out there) or unless I missed reading this, if you set it negitive it runs forever...

Yeah Scorp, thats basically what I did in my game (with a few added things to turn off the game timer for my pause script)

Hey... yeah I know there is work arounds... but damnit... I'm all about making others do the work :P

I'm sorry, don't put me in the hole again...

Then again, the hole is probably nicer than here in Iraq...

Scorpiorus

#4
Yeah, if it doesn't matter what key to press then WaitKey can be put in a loop, as CJ suggested in another thread recently:

while (WaitKey(1000)==0) {Ã,  } // wait for the player to press a key

It's even better than while (IsKeyPressed==0) since it reacts on pressing a key and not just on holding it down.

SMF spam blocked by CleanTalk