Page 1 of 1

How to get the player's input

Posted: Wed Mar 24, 2021 2:30 am
by DearDeerDee
Hello there!

I have an NPC that asks the player "What's your name?" Then the player types in the name before it's stored in a variable.

I've already used the sequence command TextInput, and I have a gameobject in the scene called "TextInputField". But nothing happens when the conversation took place. Is there a detailed document of how to set up this TextInputField somewhere? I tried to search in the forum but didn't find anything particularly useful.

Thanks!

Re: How to get the player's input

Posted: Wed Mar 24, 2021 10:24 am
by Tony Li
Hi,

Does the conversation run at all?

Does it show the text input field?

If not, are there any errors or warnings in the Console window?

For an example of using TextInput(), examine DemoScene1's Terminal conversation. It uses TextInput() to get the password from the player. (The password is 'dominate'.)

In the next node after using TextInput(), you can set the player's Display Name. Example:
  • Dialogue Text: "What's your name?"
    Sequence: TextInput(Text Field UI, Name:, playerName)
  • Dialogue Text: "Hi, [var=playerName]. Nice to meet you!"
    Script: Actor["Player"].Display_Name = Variable["playerName"]

Re: How to get the player's input

Posted: Wed Mar 24, 2021 8:13 pm
by DearDeerDee
Hi Tony, in my node I have the sequence like this:
Snipaste_2021-03-25_08-07-28.png
Snipaste_2021-03-25_08-07-28.png (24.7 KiB) Viewed 1017 times
This is the node afterwards:
Snipaste_2021-03-25_08-07-43.png
Snipaste_2021-03-25_08-07-43.png (35.59 KiB) Viewed 1017 times
When I played this conversation, there was nothing on screen when the first node played. Then the second node played out as "Hi, Nice to meet you". It seems that there was nothing stored in the variable of PlayerName.

Re: How to get the player's input

Posted: Wed Mar 24, 2021 8:49 pm
by Tony Li
Hi,

Is your text field UI named "TextFieldUI" (no spaces) or "Text Field UI" (with spaces)? Make sure the name matches exactly.

Also try setting some text in the first node's Dialogue Text field, such as "What is your name?"

Re: How to get the player's input

Posted: Wed Mar 24, 2021 10:07 pm
by DearDeerDee
Hi,

I tried to add a dialogue when the input window should pop up yet still nothing happens.

However, I noticed that I don't have a TextFieldUI gameObject compared to the demo.
Snipaste_2021-03-25_10-04-25.png
Snipaste_2021-03-25_10-04-25.png (16.93 KiB) Viewed 1015 times
How can I create this TextFieldUI gameObject in my project? Is there any documented tutorial available?

Re: How to get the player's input

Posted: Wed Mar 24, 2021 10:25 pm
by Tony Li
Hi,

You can copy it from one of the prefabs. For example:

1. Open the Basic Standard Dialogue UI prefab.

2. Expand it until you see Text Field UI.

3. Right-click on Text Field UI and select Copy.

4. Inspect your own dialogue UI.

5. Right-click on Dialogue Panel and select Paste.

6. Inspect it in the Scene view to make sure it's positioned where you want and looks the way you want.

Re: How to get the player's input

Posted: Wed Mar 24, 2021 10:42 pm
by DearDeerDee
Hi Tony,

I don't have my own dialogue UI. So far I am using the basic standard dialogue ui, set in the dialogue wizard.
Snipaste_2021-03-25_10-39-59.png
Snipaste_2021-03-25_10-39-59.png (50.77 KiB) Viewed 1015 times

Re: How to get the player's input

Posted: Wed Mar 24, 2021 10:48 pm
by DearDeerDee
Hi Tony,

I dragged a Computer Standard Dialogue UI prefab into my scene as a child of world space canvas. Then I checked and realized that the Text Field UI game object has spaces while my sequencer doesn't. After the modification, the input window pops up in the conversation and the variable is stored!

Thanks so much for your detailed responses! They are super helpful!

Re: How to get the player's input

Posted: Wed Mar 24, 2021 10:48 pm
by Tony Li
Glad to help! :-)