"Pausing" a script until the player provides a text input

Started by graysond, Mon 09/12/2024 20:28:31

Previous topic - Next topic

graysond

Hello!

I have created a custom gui with a text box, and I know how to use the "OnActivate" event. But here's a use case I can't figure out:

I would like a character to say some dialogue, then the player to provide a text input while the script waits for this input, then the character to respond to that input.

The problem I run into is that if I call the gui with the text box, the script continues to run. I would like the game to wait until an OnActivate event is called.

As an example:

Code: ags
{
cRoger.Say("What would you like for breakfast?");
// A custom gui pops up with a text box. The script does not continue until the player enters text and that text is stored as string via OnActivate.
cRoger.Say("[TOAST], eh? I can do that.");
}

Another scenario might be: A character asks the player "What's your name?", the player is prompted to give a name, then the conversation continues.

The default Game.InputBox seems to work like this normally, as if it's calling a special wait function, but I don't know how to achieve the same behavior with a custom gui.

I have found some workarounds for my specific use case but they are inefficient. But that said, because I have something that works I am mostly interested in the "best" way to do this rather than other workarounds.

Thanks in advance!

Crimson Wizard

#1
In AGS you cannot pause a script in the middle to receive GUI input or user input. Meaning you can wait in the middle using Wait command or a blocking action, but during that GUIs won't react to input, and events like "on_key_press" and "on_mouse_click" won't run.

The common way is to break the script into 2 parts, one run before the input and another after.

How to do that depends on whether this is a regular script or a dialog script.
For instance, if done in dialog script, you could implement 2 parts as 2 separate topics, and have dialog options with text input box shown in the middle (there's a setting in Dialog that allows to show input box in dialog options).

With regular script, you will have to finish the first part with displaying a GUI with text box (possibly the GUI with "Pause game when shown" style), and run the second part when that particular text box receives OnActivate event.

Rik_Vargard

I don't know if this is useful but I had that moment when the player had to put a phrase as a password.
So I just had a GUI with a textbox for the player to fill in.

And My code was

Code: ags

if (tbPassword.Text == "Blablabla")
  {
   And here comes the aftermath
  }

graysond

Thanks for the replies!

If I'm understanding everything, it seems like there's no way to get a player-inputted string in the middle of a script besides tossing things to a separate script. Unfortunate!

eri0o

If you ignore different keyboard layouts, ignore anything beyond English, and can do some scripting, you can hack your Game.InputBox like by using the wait functions with their skip reason

https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Wait.html

You can still use the mouse input as skip reason combined with their positions if you also want to accept hits in a keyboard image (say for minimal touch support). Also forget the textbox, use a label and then assemble the text and use the label to present the text.

Anyway, not pretty but can be done without too many lines.

SMF spam blocked by CleanTalk