Author Topic: how to stop advancement of a script until only leftmouse is clicked (solved!)  (Read 751 times)

my2k

  • Posts: 16
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: Adventure Game Studio
  1. void DisplayDialogue(this Character*, String message, bool isprofleft, int textcolour)
  2. {
  3.    Dispgui.Visible = true;
  4.   gBottomBar.Visible = true;
  5.   gDialogue.Visible = true;
  6.  
  7.   TextDialogue.Text = message;
  8.    TextDialogue.TextColor = textcolour;
  9.  
  10.     if (isprofleft == true)
  11.   {
  12.     Dispgui.SetPosition(45, 250);
  13.   }
  14.   else
  15.   {
  16.     Dispgui.SetPosition(520, 250);
  17.    }
  18.  
  19. while (WaitMouseKey(1000)==0) {  }
  20.  
  21.  gDialogue.Visible = false;
  22.   gBottomBar.Visible = false;
  23.   Dispgui.Visible = false;
  24.  
  25. }
  26.  
  27.  

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

Code: Adventure Game Studio
  1.   btnProfileView.Animate(3, 1, 10, eRepeat);
  2.   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: Adventure Game Studio
  1. while (IsButtonDown(eMouseLeft)==0);
  2. {
  3. }

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!
« Last Edit: 20 Jan 2017, 03:17 by my2k »

Mandle

  • Posts: 7,891
  • NO PIXEL LEFT BEHIND!!!
    • Mandle worked on a game that was nominated for an AGS Award!
Something like this?

Code: Adventure Game Studio
  1. while (mouse.IsButtonDown(eMouseLeft)==0)
  2.  {
  3.  }
« Last Edit: 18 Jan 2017, 09:35 by Mandle »

Snarky

  • Global Moderator
  • Posts: 6,750
  • Private Insultant
    • I can help with proof reading
    • I can help with translating
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

  • Posts: 10,676
  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on a game that was nominated for an AGS Award!
This should work:
Code: Adventure Game Studio
  1.   while (!mouse.IsButtonDown(eMouseLeft)) Wait(1);
« Last Edit: 18 Jan 2017, 13:36 by Khris »

Mandle

  • Posts: 7,891
  • NO PIXEL LEFT BEHIND!!!
    • Mandle worked on a game that was nominated for an AGS Award!
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

  • Posts: 16
thank you for your help everyone!

This should work:
Code: Adventure Game Studio
  1.   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

  • Posts: 10,676
  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on a game that was nominated for an AGS Award!
Right, use this:

Code: Adventure Game Studio
  1. // global header
  2. import void WaitMouse();
  3.  
  4. // top of global script
  5. void WaitMouse() {
  6.   while (!mouse.IsButtonDown(eMouseLeft)) Wait(1);
  7.   while (mouse.IsButtonDown(eMouseLeft)) Wait(1);
  8. }

In your script, just use WaitMouse();

my2k

  • Posts: 16
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-)