A GUI that works EXACTLY like Game.InputBox but with no character limit

Started by Abisso, Sat 01/12/2012 18:22:39

Previous topic - Next topic

Abisso

Hello colleagues.

It's been a while since I asked for something related to scripting but after several frustrating hours spent with no significant result, I decided it could have been worth asking. I truly hope this matter has not been asked elsewhere, but a thorough search didn't reveal anything relevant.

What I need is to implement a script that works EXACTLY like Game.InputBox, but with a custom GUI. Hehe, now most of you would probably think it's the same old question about a custom InputBox. Well, it's not, of course.

If you use the breakdown debug feature in AGS and you place the breakpoint on this line of code:

Game.InputBox("Type in something");

you will see that after the line is executed, no other script will be, until the user presses Return or one of the buttons in the InputBox.

I haven't been able to replicate this effect no matter how hard I tried. PauseGame() is not a good option as the code still gets executed and the same thing happens if I set the GUI Visibility as "Pause game when shown".

To elucidate more on why I need such a thing, the reason is I want this GUI to become Visible when the user presses a certain key and this should be possible in any room and even during blocking scripts. No other line of code should be executed until the user has pressed RETURN and of course he should be able to type in the textbox before that happens.

Thanks for reading.
Welcome back to the age of the great guilds.

Khris

What specifically continues to execute while the GUI is shown?

Abisso

Hello Khris and thanks for your interest.

The function that makes the custom InputBox Visible gets called inside repeatedly_execute_always. It executes some lines of code, then makes the custom InputBox Visible, and then does something else.

What continues to execute (even when PauseGame() gets called) are the following lines of code in the same function and then all the code inside repeatedly_execute_always.
Which makes sense, of course, since "always" means "always".

But still, when Game.InputBox is called, not even that portion of the code executes and yet the user is able to type in the built-in InputBox.
When the game is paused with PauseGame() or with a Popup GUI instead, the user can't type anything in the custom InputBox (because on_key_press never gets the chance to be called).
I read somewhere during my researches about this topic that there are only a small number of situations when the script is REALLY paused, one of them being the Display function being called. Unfortunately I can't recall where I read that, but I'm almost sure it was CJ himself who wrote it.

By the way, in the meantime I figured out a workaround to allow the player to type in the InputBox even in that uncomfortable situation. The solution isn't particularly elegant nor compact, but still should work (I have to test it, and I'm too tired to at the moment). Basically I'll need to add an IsKeyPressed check inside the repeatedly_execute_always function for EACH character I want the user to be able to type and if the check returns true Append the character to the textbox.Text.

I'm still open to more elegant suggestions though, e.g. one that stops the scripts from being executed but still accepts keyboard inputs (like Game.InputBox does).
Welcome back to the age of the great guilds.

Khris

Quote from: Abisso on Sun 02/12/2012 02:52:27When the game is paused with PauseGame() or with a Popup GUI instead, the user can't type anything in the custom InputBox (because on_key_press never gets the chance to be called).
Not true, it's just that both on_key_press and on_mouse_click have code in them that prevents normal execution if the game is paused.
In on_key_press for instance, after lots of code that handles the game-pausing gPanel GUI, there's this:
Code: ags
  if (IsGamePaused() || (IsInterfaceEnabled() == 0))
  {
    // If the game is paused with a modal GUI on the
    // screen, or the player interface is disabled in
    // a cut scene, ignore any keypresses.
    return;
  }

Only after that is all the standard key handling. So it's perfectly possible to use on_key_press while the game is paused (implementing a simple pause GUI would already be a nuisance otherwise).

The same is true for on_mouse_click, which has the part that disables it while the game it paused right at the start.

Abisso

First of all, I forgot to mention I'm using AGS 3.1.2 SP1. My bad, cause maybe something worked / works differently in other versions.

That said, you're correct about both on_key_press and on_mouse_click, of course. What I said was incomplete: on_key_press (and probably also on_mouse_click) doesn't get called when the game is paused during a blocking script. I tested this and I'm sure.

For the same reason you can't pause/unpause the game during, let's say, a blocking animation, unless you put something like this inside repeatedly_execute_always:

if (isKeyPressed(eKeySpace)) PauseGame();

Which isn't exactly a nuisance, after all, but still not particularly straightforward for a newbie, I guess. Being unable to pause the game inside a blocking script makes pausing itself almost useless, in my opinion.

Even f you do this, anyway, the code inside repeatedly_execute_always still gets executed after the PauseGame() command.

The workaround I suggested is the only usable one I've found at the moment to recognize keyboard input in such a situation, and it works (tested it). As per the other half of the problem, which ironically it's exactly the fact the code inside repeatedly_execute_always continues to be executed during a pause (including the rest of the function that calls PauseGame()) I will find some workaround, I'm sure.

I'm not really satisfied with such an inelegant solution to an apparently simple problem: being able to customize the standard InputBox would have been a wonderfully easy and clean one instead. But at least it works.
Welcome back to the age of the great guilds.

SMF spam blocked by CleanTalk