Is there a way to pause the script until the player or user clicks?
I am looking for a function similar to WaitMouseKey, without the timeloops.
Try this:
function on_mouse_click(MouseButton button) {
Ã, if (IsGamePaused()) {
Ã, Ã, if (button==eMouseLeft) UnPauseGame();
Ã, }
Ã, else {
Ã, Ã, ...
Ã, }
}
Then, whenever you want to pause the script, call
PauseGame();If that's not enough, use this:
while (!Mouse.IsButtonDown(eMouseLeft));
and disable the while check first which ends the game when the while loop reaches 150'000 iterations. (possible since 2.71 beta 4).
There's just one problem. PauseGame doesn't pause the scripts.
For example,
gDisplay.visible = true;
PauseGame();
gDisplay.visible = false;
Even if the game is "paused", the script will go on and close gDisplay.
I want the game to await the player's click before closing gDisplay.
Well KhrisMUS's second suggestion should "sort of" work, as it missed some important thing:
while (!Mouse.IsButtonDown(eMouseLeft)) Wait(1);
(and you should disable teh while loop check as mentioned, or else the game will be terminated after 150000 or so loops, which would be like, er... an hour under default game speed of 40FPS).
Like this:
function noloopcheck wait_click() {
Ã, while (!mouse.IsButtonDown(eMouseLeft));
}
Is the Wait(1); really necessary?
Yes, very important, otherwise you'll be stuck in the same game frame.
So mouse.IsButtonDown() is only updated every other frame?
Good to know, I guess this is the case for all (similar) functions?
I'm not quite sure where this is going.Ã, What does (!Mouse.IsButtonDown(eMouseLeft)) Wait(1); have to do with what I'm trying to do?Ã, The function probably makes sense , but I don't know what to do with it.
Basically, I'm having a GUI appear with a label inside it. I want so that every time the user clicks on the screen, the label changes it's caption.
I want to be able to do this multiple times in the game.
gDisplay.Visible = true;
Labelname.SetText("Hello.");
//Then the user clicks
Labelname.SetText("My name is Joe.");
//Then the user clicks
Labelname.SetText("I like Jell-O.");
//Then the user clicks
gDisplay.Visible = false;
The function calls Wait(1); until mouse.IsButtonDown(eMouseLeft) equals true i. e. the player presses the left mouse button.
So, put this somewhere in the global script:
function noloopcheck wait_click() {
Ã, while (!mouse.IsButtonDown(eMouseLeft)) Wait(1);
}
Import the function in the script header:
import function wait_click();
Then call it everytime you want the game to pause until the player clicks:
gDisplay.Visible = true;
Labelname.SetText("Hello.");
wait_click();
Labelname.SetText("My name is Joe.");
wait_click();
Labelname.SetText("I like Jell-O.");
wait_click();
gDisplay.Visible = false;
Almost!
If I click once, the GUI turns off.Ã, The game executes all three wait_clicks at the same time.
Quote from: KhrisMUC on Thu 16/03/2006 10:34:09
So mouse.IsButtonDown() is only updated every other frame?
I don't know, probably
not, but you SHOULD add wait to it, otherwise the while loops will be stuck in the same
game loop that may cause slowdowns and other problem (most possibly freeze your game as the screen won't update during it, and background fucntions like rep_exe_always() won't run).
Quote from: Mugs on Thu 16/03/2006 22:35:18
Almost!
If I click once, the GUI turns off.Ã, The game executes all three wait_clicks at the same time.
Solved it!Ã, I inserted...
function noloopcheck wait_unclick() {
Ã, while (mouse.IsButtonDown(eMouseLeft)) Wait(1);
}
...in the global script.
Then I did the following:
gDisplay.Visible = true;
Labelname.SetText("Hello.");
wait_click();
Labelname.SetText("My name is Joe.");
wait_unclick();
wait_click();
Labelname.SetText("I like Jell-O.");
wait_unclick();
wait_click();
gDisplay.Visible = false;
Thanks for all the help!!!!
Sorry, I was tired :)
Just change the original function:
function noloopcheck wait_click() {
Ã, while (!mouse.IsButtonDown(eMouseLeft)) Wait(1);
Ã, while (mouse.IsButtonDown(eMouseLeft)) Wait(1);
}
You won't need wait_unclick then.
Why's the second while needed? So the wait will end when the button is released?
Yes, otherwise
QuoteAlmost!
If I click once, the GUI turns off.Ã, The game executes all three wait_clicks at the same time.