Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: my2k on Wed 18/01/2017 08:40:52

Title: how to stop advancement of a script until only leftmouse is clicked (solved!)
Post by: my2k on Wed 18/01/2017 08:40:52
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) Select

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) Select

  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) Select

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!
Title: Re: how to stop advancement of a script until only leftmouse is clicked
Post by: Mandle on Wed 18/01/2017 09:33:24
Something like this?


while (mouse.IsButtonDown(eMouseLeft)==0)
{
}
Title: Re: how to stop advancement of a script until only leftmouse is clicked
Post by: 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.)
Title: Re: how to stop advancement of a script until only leftmouse is clicked
Post by: Khris on Wed 18/01/2017 13:34:15
This should work:
  while (!mouse.IsButtonDown(eMouseLeft)) Wait(1);
Title: Re: how to stop advancement of a script until only leftmouse is clicked
Post by: Mandle on Thu 19/01/2017 01:57:29
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.
Title: Re: how to stop advancement of a script until only leftmouse is clicked
Post by: my2k on Thu 19/01/2017 05:07:45
thank you for your help everyone!

Quote from: Khris on Wed 18/01/2017 13:34:15
This should work:
  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)?
Title: Re: how to stop advancement of a script until only leftmouse is clicked
Post by: Khris on Thu 19/01/2017 11:50:20
Right, use this:

// 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();
Title: Re: how to stop advancement of a script until only leftmouse is clicked
Post by: my2k on Fri 20/01/2017 03:16:44
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-)