How to pause speech when custom choice GUI is displayed [SOLVED]

Started by Stranga, Mon 27/11/2017 02:54:20

Previous topic - Next topic

Stranga

Hello everyone,

I am having trouble with a custom choices GUI I made. It pops up with a yes or no choices which each selection is chosen with the keyboard since this is a completely keyboard controlled game.

The trouble is when I have the GUI displayed everything works fine, BUT, the speech and text keeps going on in the background. What I'm trying to achieve is that when the CHOICE is selected (YES or NO) the text will change depending upon what choice the player makes. I have placed this on a stand on hotspot event.

Khris

First of all: don't use the stand on hotspot event. That's really old, from a time when AGS didn't have regions. Use a region and its "player walks on region" event instead (which in addition will only fire once, not every game loop).

What you want to do requires splitting up your code into more than one function.First, you show some dialogue, then show the GUI, then exit the function. When the player has made a choice, more code runs, depending on the choice. Here's example code:

Code: ags
// room script
int choice = 0;

// this function is generated by AGS once you add the event to the region
function region1_walksOnto() {
  player.Say(...);
  cGuy.Say(...);
  ...
  choice = 1;
  gYesOrNo.Visible = true;  // this gui's visibility should be modal I guess
}

function choice1(bool yes) {
  if (yes) {
    // player chose yes
  }
  else {
    // player chose no
  }
}

function on_key_press(eKeyCode k) {
  if (gYesOrNo.Visible && (k == eKeyY || k == eKeyN)) {
    if (choice == 1) choice1(k == eKeyY);
    // if (choice == 2) choice2(k == eKeyY);
  }
}


Should be pretty self explanatory. Anytime the player presses Y or N in the room, the game checks if the Y/N GUI is visible, and if so, calls a function based on the choice variable, passing true if the player typed Y. In this function (choice1() in my example), the dialog continues.

Stranga

Funny you should mention that! I spent all afternoon changing stand on hotspots to regions haha! (Should have done that ages ago)

And I see what you're saying, the only thing is I have a cursor that selects yes or no which is controlled in my global script via keyboard. Would this method still work with that or would I have to transfer the keyboard lines to the room script?

EDIT: I should have read carefully before typing (Sorry). Thank you, it works great! :)

SMF spam blocked by CleanTalk