Set player name during conversation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
fyperia
Posts: 13
Joined: Sat Jul 25, 2020 8:16 pm

Set player name during conversation

Post by fyperia »

Hi! I'd like to allow the player to set their name during the first conversation of the game. I'm using the text input field from the basic UI prefab and this sequence:

Code: Select all

TextInput(Text Field UI,Name:,playerName);SetContinueMode(false)
With this sequence and script in the following node:

Code: Select all

SetContinueMode(true);{{default}}

Actor["Player"].Display_Name = Variable["playerName"]
However, when I type in the name and press enter, nothing happens. If I remove the SetContinueMode, it just uses the default playerName value on the next piece of dialogue. Am I missing something?
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set player name during conversation

Post by Tony Li »

Hi,

Use the ChangeActorName() Lua function.

The Dialogue System cache the participants' names at the start of the conversation so it doesn't have to take time to look up the name with every subtitle. This is good for performance, but the downside is that you need to tell the Dialogue System that you've changed the underlying Display Name by using ChangeActorName().

So assuming your dialogue entry has this Sequence:

Code: Select all

TextInput(Text Field UI,Name:,playerName);
SetContinueMode(false)
Set the next dialogue entry's Sequence to:

Code: Select all

SetContinueMode(true)
and its Script to:

Code: Select all

ChangeActorName("Player", Variable["playerName"]);
Variable["Actor"] = Variable["playerName"]
fyperia
Posts: 13
Joined: Sat Jul 25, 2020 8:16 pm

Re: Set player name during conversation

Post by fyperia »

That's super helpful and likely would have been my next question! But I should have been more clear about my problem -- the conversation doesn't advance when I hit enter. Before I disabled the continue button, it would just use the default name. So I guess my actual question is how do I get the input from the text field to actually be confirmed and stored in the variable?
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set player name during conversation

Post by Tony Li »

Hi,

If your Sequence looks like this:

Code: Select all

TextInput(Text Field UI,Name:,playerName);
SetContinueMode(false)
then it should automatically advance when you press Enter. This is because SetContinueMode(false) tells it to not wait for a continue button click, and TextInput() ends when you press Enter. Since the sequence isn't waiting for a continue button click, it will end when TextInput() ends.
fyperia
Posts: 13
Joined: Sat Jul 25, 2020 8:16 pm

Re: Set player name during conversation

Post by fyperia »

It looks like my issue was with the Input System not being set up properly and not with the dialogue sequence, which I didn't catch because clicking the continue button was working. Thanks for the help!
User avatar
Tony Li
Posts: 21973
Joined: Thu Jul 18, 2013 1:27 pm

Re: Set player name during conversation

Post by Tony Li »

Happy to help. Glad you found the issue!
Post Reply