Hi,
I want to be able to, in the "Dialogue Text" of one of my conversations, have an actor mention a name saved in player prefs under a string.
For example:
"Oh hi (PlayerPrefs.GetString("playername") nice to see you."
It's based on player input, so how can I access whatever the player inputs in the dialogue system conversation node?
Get PlayerPrefs String during Dialogue
Re: Get PlayerPrefs String during Dialogue
Hi,
There are two ways to do this:
1. Use the TextInput() sequencer command to read player input during a conversation and store it in a Dialogue System variable (more info). If you set up the save system, the variable value will be saved in saved games. Use the [var=variable] markup tag in your dialogue text to show the variable value. See here for example scene: How To: Read Input From Player During Conversations
2. Or register the PlayerPrefs.GetString() with Lua (info, tutorial). Then use the [lua(code)] markup tag to call PlayerPrefs.GetString("playername") in your text.
There are two ways to do this:
1. Use the TextInput() sequencer command to read player input during a conversation and store it in a Dialogue System variable (more info). If you set up the save system, the variable value will be saved in saved games. Use the [var=variable] markup tag in your dialogue text to show the variable value. See here for example scene: How To: Read Input From Player During Conversations
2. Or register the PlayerPrefs.GetString() with Lua (info, tutorial). Then use the [lua(code)] markup tag to call PlayerPrefs.GetString("playername") in your text.
-
- Posts: 3
- Joined: Sun Dec 04, 2022 7:25 am
Re: Get PlayerPrefs String during Dialogue
Thank you so much for the help! I registered a function in Lua called "playername" like this:
And then I created a function called PlayerName like this:
but when I type in in the dialogue text, it comes out as nil. Any reason why this would be?
Code: Select all
Lua.RegisterFunction("player", this, SymbolExtensions.GetMethodInfo(() => PlayerName(string.Empty)));
Code: Select all
public void PlayerName(string message)
{
message = PlayerPrefs.GetString("playername");
}
Code: Select all
[var=player]
Re: Get PlayerPrefs String during Dialogue
Hi,
Change your C# method to:
and register it with Lua like this:
Use it in your Dialogue Text like this:
Change your C# method to:
Code: Select all
public string PlayerName()
{
return PlayerPrefs.GetString("playername");
}
Code: Select all
Lua.RegisterFunction("player", this, SymbolExtensions.GetMethodInfo(() => PlayerName()));
- Dialogue Text: "Hello, [lua(player())]."
-
- Posts: 3
- Joined: Sun Dec 04, 2022 7:25 am
Re: Get PlayerPrefs String during Dialogue
Omg thank you!!!! It finally worked.
Re: Get PlayerPrefs String during Dialogue
Happy to help!