text box input (String input = txtUserInput.Text) not working

Started by kelp, Fri 27/04/2018 00:54:14

Previous topic - Next topic

kelp

Here's the code I've got:

Code: ags

function cDanielle_Talk()
{
  cElle.FaceCharacter(cDanielle);
  if (DanTalk==0)
  {
    dDan1.Start();
    DanTalk=1;
  }
  else if(DanTalk==1)
  {
    dDan4.Start();
    if (dDan4.HasOptionBeenChosen(1))
    {
      String input = txtUserInput.Text;
      Parser.ParseText(input);
      if (Parser.Said("window"))
      {
        cDanielle.Say("xxx");
        cDanielle.Say("xxxxx");
      }
      else
      {
        cDanielle.Say("xxxxxxx");
      }
    }
    else
    {
      cDanielle.Say("xxxxxxxx")
    }
  }
}


When I attempt to run this, I get this error code: undefined symbol 'txtUserInput'

I took this section of the code directly from the manual, so I'm at a loss. But also I've never attempted to use the parser before, so it's probably user error.

Thanks in advance!

Crimson Wizard

You need to create a GUI with TextBox item on it, called "txtUserInput".

Examples from the manual often assume you create necessary items before using the code.

kelp

Quote from: Crimson Wizard on Fri 27/04/2018 01:06:35
You need to create a GUI with text parser item on it, called "txtUserInput".
...any guides on that? I wasn't able to find anything in the manual about creating new GUIs for text parser/input. Thanks!

Crimson Wizard

#3
Sorry, I meant "Text Box item".
When in GUI editor, hover mouse over toolbar and find one with "Add GUI Text box" hint.

Simply place one on the GUI, either create new GUI for that, or place it on existing one, whichever suits your game design.
Then rename it to match the code (txtUserInput).

One important thing to remember is that when TextBox is visible on screen it will capture all keypresses.

kelp

Thank you for the play by play! (The manual is usually great...until you get to these sorts of things!)

I tried this, but when I tried to enter a script name of txtUserInput, I got the error that something else already had that script name...but I have no idea what thing that is, or where to find it. :/

Found it. But now when I playtest, the GUI doesn't appear when it's supposed to...

Crimson Wizard

Quote from: kelp on Fri 27/04/2018 01:20:43
But now when I playtest, the GUI doesn't appear when it's supposed to...

Unless configured to be shown from the start (Visibility property is "Normal, initially on" or "Always shown"), GUI appear when you tell it to, with command like GuiName.Visible = true. Do you have such command in the script?

kelp

Yup, I've added that here:

Code: ags

 else if(DanTalk==1)
  {
    dDan4.Start();
    if (dDan4.HasOptionBeenChosen(1))
    {
      gGui1.Visible=true;
      String input = txtUserInput.Text;
      Parser.ParseText(input);
      if (Parser.Said("window"))
      {
        cDanielle.Say("xxx.");
        cDanielle.Say("xxxxxx");
      }
      else
      {
        cDanielle.Say("xxxxxxxxxx");
      }
    }


gGui1 is the textbox gui in question (lazy name because lazy)

Alright. New issue with it:

The GUI is coming up, but not when I have it scheduled to. The GUI doesn't appear until after I've "talked" to cDanielle twice, when it should happen immediately after the dDan4 stops. Not sure why.

Crimson Wizard

#7
Ok, I did not pay much attention to this earlier, but your script does not look right.

You probably intended to have some actions happening after dialog finished, but it does not work like that.
Dialog is actually run only after current function ends. So what will happen is that dDan4.Start() command will schedule dialog, then, since no options were chosen yet, it will skip all the commands until the end of the function, and start the dialog only after.

Dialog.HasOptionBeenChosen does not do what you probably thought: it does not tell that this option was JUST chosen, it tells that some option was chosen at least once in the past, but that could happen long time ago.

Similar thing is wrong about parser. gGui1.Visible=true will only make it visible, but it won't wait for user input there. Instead it will immediately follow to Parser.ParseText(input) command, but since user did not have a chance to type in anything, the text will always be empty and parsing won't work.

You need to remake all this... split into two or maybe even three functions:
1) one that starts the dialog,
2) another that is probably run the from the dialog script when user chooses some option; it should display the parser GUI;
3) third that is run when TextBox sends OnActivate event, and checks the user input.

The biggest mistake here is a misconception about how commands run. Most of those commands in this function are non-blocking, which means game won't wait, and continue to run following commands immedaitely.

You need to learn how to divide the complex process into stages, that may be separated by a period of time between them.

kelp

Alright, so I am definitely unclear on how to separate this into multiple functions and go from one to the next. Got any examples of this? Thanks again.

Khris

You need to tell us what you actual problem is instead of asking about your attempt at solving it.
It looks like you want the user to enter text mid-dialog?

SMF spam blocked by CleanTalk