Page 1 of 1
Set player name during conversation
Posted: Mon Aug 15, 2022 6:04 pm
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?
Re: Set player name during conversation
Posted: Mon Aug 15, 2022 8:06 pm
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:
and its Script to:
Code: Select all
ChangeActorName("Player", Variable["playerName"]);
Variable["Actor"] = Variable["playerName"]
Re: Set player name during conversation
Posted: Tue Aug 16, 2022 2:17 am
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?
Re: Set player name during conversation
Posted: Tue Aug 16, 2022 10:16 am
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.
Re: Set player name during conversation
Posted: Tue Aug 16, 2022 3:26 pm
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!
Re: Set player name during conversation
Posted: Tue Aug 16, 2022 3:37 pm
by Tony Li
Happy to help. Glad you found the issue!