Page 1 of 2
How to Input name?
Posted: Fri Sep 03, 2021 8:25 pm
by mac
So Tony, I'm using the JRPG template, and my game starts with a dialogue, and it goes like this:
The protagonist name is hidden, his name in the dialogue starts as (....). The protagonist is suddenly teleported into another world while he sleeps. He is teleported in the middle of a road, where he finds a rat humanoid.
First, the rat asks his name, where the player should input his name. (As I'm using the JRPG template this should not be hard I'm assuming?). So the protagonist name in the dialogue now and forever should be this string that the player has written.
Secondly, the rat introduces himself, so before that, his dialogue name would be something like "Rat Guy", and after introducing himself, his dialogue name would now become Romulus.
How can I achieve those two things?
Thank you in advance.
Re: How to Input name?
Posted: Fri Sep 03, 2021 9:08 pm
by Tony Li
Hi,
To input the protagonist's name, use the
TextInput() sequencer command to input the name and store it in a variable. In the next node, assign that variable to the player actor's Display Name. Example:
- Dialogue Text: "What's your name?"
- Sequence: TextInput(Text Field UI, Name:, playerName)
...
(Next node:)
- Dialogue Text: "Nice to meet you, [var=playerName]."
Script: Actor["Player"].Display_Name = Variable["playerName"]
To reveal a name during a conversation, see the Discover Name Example on the
Dialogue System Extras page.
Re: How to Input name?
Posted: Sat Sep 04, 2021 3:07 am
by mac
Thank you Tony, the first node works just fine I guess, but the second doesn't play the string, throwing this error:
Code: Select all
Dialogue System: Lua code 'Actor["Player"].Display_Name = Variable["playerName"];
' threw exception 'Cannot assign to a null value. Are you trying to assign to a nonexistent table element?.'
Re: How to Input name?
Posted: Sat Sep 04, 2021 6:21 am
by Tony Li
Hi,
That Script line makes the assumption that the player actor in your database has the Name "Player". If you've changed the Name field, use the value that you set it to. For example, if you set the player actor's Name to "Protagonist":
Actor["Protagonist"].Display_Name = Variable["playerName"]
Note that you may instead want to use the Lua function that's in the Discover Name Example I mentioned above.
Re: How to Input name?
Posted: Tue Apr 05, 2022 11:24 pm
by mac
Hey Tony, I got the NPC Actor to say the player input name (John in the screenshot case), but how can I now change the players actor name from "...." (before inputting his name) to the chosen name? Do I also use the Discover Name Example for the player Actor?
Re: How to Input name?
Posted: Tue Apr 05, 2022 11:45 pm
by Tony Li
Hi,
Yes, use the same process for any actor (player or NPC).
Re: How to Input name?
Posted: Thu Apr 07, 2022 2:05 am
by mac
Nice Tony, everything works now, but I imagine that the Player Actor name doesn't change forever after you input the playerName variable, is there any script or anything I can run to overwrite the Player Actor name with the variable?
Re: How to Input name?
Posted: Thu Apr 07, 2022 8:34 am
by Tony Li
Hi,
The player actor's name is stored in the Lua variable Actor["Player"].Display_Name.
If you use the
save system and a Dialogue System Saver, this Lua variable will be saved.
If you don't use the save system, you can save the Lua variables to a string using PersistentDataManager.GetSaveData() and restore them using PersistentDataManager.ApplySaveData(string).
Re: How to Input name?
Posted: Mon Apr 25, 2022 9:01 pm
by mac
Makes sense, but how do I exactly access the playerName variable we created? We didn't use any custom Sequencer command until now so I'm not sure how to store it with the PersistentDataManager.GetSaveData();, which I assume you can only use inside a script and not in the Sequence space of the dialogue entry.
I assume I have to create a Custom Sequencer Command, I did it and tried what I thought would work:
Code: Select all
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
public class SequencerCommandSavePlayerName : SequencerCommand
{ // Rename to SequencerCommand<YourCommand>
public void Awake()
{
string playerName = PersistentDataManager.GetSaveData(); //nullref here.
SaveManager.Instance.state.playerName = playerName; // My custom save manager.
print("Player name is: " + playerName);
Stop();
}
}
}
Thanks in advance.
Re: How to Input name?
Posted: Mon Apr 25, 2022 9:39 pm
by Tony Li
mac wrote: ↑Mon Apr 25, 2022 9:01 pmMakes sense, but how do I exactly access the playerName variable we created?
I don't quite follow. For what reason do you need to access the playerName variable? It should really just be used as a temporary intermediate variable to hold the result of the TextInput() sequencer command until you copy the playerName variable's value to Actor["Player"].Display_Name. If you need the player's display name to change in the middle of the conversation, which I assume you do, change it using the Lua function in the Discover Name example.
But, to answer your question, you can use the DialogueLua class to access the playerName variable in C#.
Code: Select all
string playerName = DialogueLua.GetVariable("playerName").asString;
// You can also use DialogueLua to get an actor's Display Name:
string playerName = DialogueLua.GetActorField("Player", "Display Name").asString;