how to stop advancement of a script until only leftmouse is clicked (solved!)

Started by my2k, Wed 18/01/2017 08:40:52

Previous topic - Next topic

my2k

Hi there.

I have a custom-ish dialogue script, cobbled together with the gracious help of threads on here!
Basically it displays a profile picture gui that you can position with a boolean, a background gui, and a text until a player clicks the mouse to advance it on to the next dialogue line.

Code: ags

void DisplayDialogue(this Character*, String message, bool isprofleft, int textcolour)
{
   Dispgui.Visible = true;
  gBottomBar.Visible = true;
  gDialogue.Visible = true;
  
  TextDialogue.Text = message;
   TextDialogue.TextColor = textcolour;
  
    if (isprofleft == true)
  {
    Dispgui.SetPosition(45, 250);
  }
  else
  {
    Dispgui.SetPosition(520, 250);
   }

while (WaitMouseKey(1000)==0) {  }

 gDialogue.Visible = false;
  gBottomBar.Visible = false;
  Dispgui.Visible = false;
 
}



and, as said, it waits until you click the mouse to go to the next dialogue, which in-situ looks like this:

Code: ags

  btnProfileView.Animate(3, 1, 10, eRepeat);
  cEGO.DisplayDialogue("this is test dialogue!", true, 62772);

   

however, since it's WaitMouseKey it registers keypresses as well, including useful ones like PrtScn and such. I want it to only advance forward when you click the mouse.

If I set anything to wait for a mouse click, it automatically skips right to the last line of dialogue, or it just pops up and then closes immediately, such as:

Code: ags

while (IsButtonDown(eMouseLeft)==0);
{
}


gives me an error, and I don't know if I can declare anything outside of this function to bring INTO it, since it's the first one in globalscript.asc, and since it gets imported into all other scripts. There's on_mouse_click as well but that doesn't work within this either. I'm sure there has to be some kind of extremely simple thing that I can't find, and I've looked for hours now...


my question is this: I've tried a ton of different ways and none of them seem to work, is there a simple piece of code that would simply halt the script until you click?

thanks for taking the time to read, I appreciate it!

Mandle

Something like this?

Code: ags

while (mouse.IsButtonDown(eMouseLeft)==0) 
 {
 }

Snarky

Pretty sure that's gonna crash, Mandle: it'll loop infinitely during a single cycle, and trigger the loopcheck.

(Sorry, don't have time to address the problem properly.)

Khris

This should work:
Code: ags
  while (!mouse.IsButtonDown(eMouseLeft)) Wait(1);

Mandle

Quote from: Snarky on Wed 18/01/2017 10:49:35
Pretty sure that's gonna crash, Mandle: it'll loop infinitely during a single cycle, and trigger the loopcheck.

(Sorry, don't have time to address the problem properly.)

Yeah, I was really only correcting the missing "mouse." from his code to show him why he was getting the error. Kinda was leaving the rest after that up to him.

my2k

thank you for your help everyone!

Quote from: Khris on Wed 18/01/2017 13:34:15
This should work:
Code: ags
  while (!mouse.IsButtonDown(eMouseLeft)) Wait(1);


I gave this a try and it works, but only for the first message. if I have multiple dialogues one after another, if I click to advance, it just just skips all other dialogues and terminates.

could it be a problem with the other part of the code, that defines what the dialogue is(last part of my main post)?

Khris

Right, use this:

Code: ags
// global header
import void WaitMouse();

// top of global script
void WaitMouse() {
  while (!mouse.IsButtonDown(eMouseLeft)) Wait(1);
  while (mouse.IsButtonDown(eMouseLeft)) Wait(1);
}


In your script, just use WaitMouse();

my2k

Khris, thank you so much! What a simple solution! I didn't think I could use one function inside the other.

It works like a charm! Thank you again! 8-)

SMF spam blocked by CleanTalk