I want a GUI to appear while the right mouse button is held down, and to disappear when it is released. The position of the mouse determines which mouse mode will be set.
When I run the game and right-klick, the mouse freezes, no GUI appears, and after a few seconds of holding down the button, the game exits because the game seems to be stuck (15001 repeats of "while").
I can't figure out what is wrong... the mouse cursor actually changes based on position, and if I put a feedback line ("player.Say") right before gVerbs.Visible=true, I get that feedback, but the GUI doesn't show up. GUI-visibility is set zu "Normal, initially off", so no Y-pos mistake either.
function showverbgui()
{
int x, y;
gVerbs.Visible=true; // show GUI
if (player.ActiveInventory==iItem1) bItem1.Visible=true; else bItem1.Visible=false;
if (player.ActiveInventory==iItem2) bItem2.Visible=true; else bItem1.Visible=false;
mouse.Mode=6; // cursor starts as arrow pointer
while (mouse.IsButtonDown(eMouseRight)) { // until RMB is released
x=mouse.x;
y=mouse.y;
if ((x>=115)&&(x<145)) { // first column
if ((y>=105)&&(y<135)) mouse.Mode=2;
if ((y>=135)&&(y<165)&&(player.ActiveInventory!=null)) mouse.Mode=4; // "use item" button
} else
if ((x>=145)&&(x<175)) { // second column
if ((y>=75)&&(y<105)) mouse.Mode=3;
if ((y>=105)&&(y<135)) mouse.Mode=0;
if ((y>=135)&&(y<165)) mouse.Mode=1;
} else
if ((x>=175)&&(x<205)) { // third column
if ((y>=105)&&(y<135)) mouse.Mode=5;
} else mouse.Mode=6; // cursor becomes pointer when not over symbol
}
if (mouse.Mode==6) mouse.Mode=0; // if still arrow pointer (nothing selected), walk.
gVerbs.Visible=false;
}
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
{
}
else if (button == eMouseLeft)
{
ProcessClick(mouse.x,mouse.y, mouse.Mode);
}
else // right-click, so show GUI
{
showverbgui();
}
}
You cannot do this by using a while loop in the showverbgui() function, or else the game frame won't advance at all... Well, it's not completely impossible (as long as you put a Wait() in the while loop and make the function noloopcheck) but this is not the recommended way of doing so.
A more suitable way is to check it in the repeatedly_execute(_always) () function. Just remove the while loop and the gui disable codes in the showverbgui() function and ass the below codes to repeatedly_execute(_always)() function (not tested):
if (gVerbs.Visible){
if (mouse.IsButtonDown(eMouseRight)) { // RMB is not released yet
x=mouse.x;
y=mouse.y;
if ((x>=115)&&(x<145)) { // first column
if ((y>=105)&&(y<135)) mouse.Mode=2;
if ((y>=135)&&(y<165)&&(player.ActiveInventory!=null)) mouse.Mode=4; // "use item" button
} else
if ((x>=145)&&(x<175)) { // second column
if ((y>=75)&&(y<105)) mouse.Mode=3;
if ((y>=105)&&(y<135)) mouse.Mode=0;
if ((y>=135)&&(y<165)) mouse.Mode=1;
} else
if ((x>=175)&&(x<205)) { // third column
if ((y>=105)&&(y<135)) mouse.Mode=5;
} else mouse.Mode=6; // cursor becomes pointer when not over symbol
} else { // RMB is released
if (mouse.Mode==6) mouse.Mode=0; // if still arrow pointer (nothing selected), walk.
gVerbs.Visible=false;
}
Thank you, that works!
I always forget to think of the script as one program, not as code that is executed while an interrupt of some kind checks everything in the background... Mouse movement is something for me that is not done by the code itself, but is run independently.
So during a WHILE loop, absolutely nothing happens that is not inside the loop, i.e. the game is frozen until the loop is done?
Quote from: Tamanegi on Wed 22/12/2010 15:25:57
So during a WHILE loop, absolutely nothing happens that is not inside the loop, i.e. the game is frozen until the loop is done?
Yep.