How to Input name?
How to Input name?
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.
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?
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:
(Next node:)
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"]
Re: How to Input name?
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?
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.
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?
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?
- Attachments
-
- Screenshot_4.png (127.14 KiB) Viewed 1866 times
Re: How to Input name?
Hi,
Yes, use the same process for any actor (player or NPC).
Yes, use the same process for any actor (player or NPC).
Re: How to Input name?
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?
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).
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?
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:
Thanks in advance.
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();
}
}
}
Re: How to Input name?
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;