Using C# String Variable for Actor Name and During Dialogues
Using C# String Variable for Actor Name and During Dialogues
Hi again!
I am so sorry to bother you again so soon...
I did go through all of these links before starting to write this :
viewtopic.php?f=3&t=666&p=3230
viewtopic.php?f=3&t=339&p=1507
viewtopic.php?f=3&t=850&p=4397
and this tutorial here :
http://pixelcrushers.com/dialogue_syste ... erFunction
Howerver, I might just be too "noob" still... I am really not sure what would be the best way to do it...
As stated in the Subject line, I need to insert one of my "global variable" (GV.stringPlayerName) and replace an actor name... as well as many occurances in dialogues...
Based on what I read so far, for the dialogue text, it would be something like that :
Dialogue Text: ""Hello, my name is [lua( LookupValue("MY_NAME") )]."
Now I just need to create the script to link "MY_NAME" to GV.stringPlayerName...
Also how to write "Lua:MY_NAME" inside the actor field...
Thanks INFINITELY for all your help!! Close to the end now!! We actually hosted and played the game directly from the publisher sandbox website yesterday!!
I am so sorry to bother you again so soon...
I did go through all of these links before starting to write this :
viewtopic.php?f=3&t=666&p=3230
viewtopic.php?f=3&t=339&p=1507
viewtopic.php?f=3&t=850&p=4397
and this tutorial here :
http://pixelcrushers.com/dialogue_syste ... erFunction
Howerver, I might just be too "noob" still... I am really not sure what would be the best way to do it...
As stated in the Subject line, I need to insert one of my "global variable" (GV.stringPlayerName) and replace an actor name... as well as many occurances in dialogues...
Based on what I read so far, for the dialogue text, it would be something like that :
Dialogue Text: ""Hello, my name is [lua( LookupValue("MY_NAME") )]."
Now I just need to create the script to link "MY_NAME" to GV.stringPlayerName...
Also how to write "Lua:MY_NAME" inside the actor field...
Thanks INFINITELY for all your help!! Close to the end now!! We actually hosted and played the game directly from the publisher sandbox website yesterday!!
Re: Using C# String Variable for Actor Name and During Dialogues
Hi!
1. Add an Override Actor Name component to the character.
2. In your script, set the component's overrideName:
To answer your specific player question, you could do this:
If you use portrait names in your dialogue UI, this name will appear in the portrait name field.
The player's name is stored in the Dialogue System variable "Actor", and the NPC is in "Conversant". So your NPC's Dialogue Text line could use the [var=varName] tag like this:
1. Add an Override Actor Name component to the character.
2. In your script, set the component's overrideName:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class SetActorName : MonoBehaviour {
public string newName;
void Start() {
GetComponent<OverrideActorName>().overrideName = newName;
}
}
Code: Select all
void Start() {
// Find the player GameObject:
var player = GameObject.FindObjectWithTag("Player");
if (player == null) Debug.LogError("Can't find player!");
// Get its OverrideActorName component (adding one if necessary):
var overrideActorName = player.GetComponent<OverrideActorName>();
if (overrideActorName == null) overrideActorName = player.AddComponent<OverrideActorName>();
// Set the overrideName to the global variable value:
overrideActorName.overrideName = GV.stringPlayerName;
}
The player's name is stored in the Dialogue System variable "Actor", and the NPC is in "Conversant". So your NPC's Dialogue Text line could use the [var=varName] tag like this:
- NPC Dialogue Text: "Hi, [var=Actor]! My name is [var=Conversant]."
Re: Using C# String Variable for Actor Name and During Dialogues
Thanks for the super complete answer!
However I feel bad because I dont see how that could work in my case...
As you know, I dont have actual actors in the game... I have one "imageBackground" and one "imageForeground"... which i change sprites all the time... so i cannot have an actual component to any gameobject... i need to do all of that in lua in the dialogue manager...
the is never a "player" gameobject... so i cant assign a tag either... the player only exist as an "actor" in the dialogue manager which i manually put in some conversations...
However I feel bad because I dont see how that could work in my case...
As you know, I dont have actual actors in the game... I have one "imageBackground" and one "imageForeground"... which i change sprites all the time... so i cannot have an actual component to any gameobject... i need to do all of that in lua in the dialogue manager...
the is never a "player" gameobject... so i cant assign a tag either... the player only exist as an "actor" in the dialogue manager which i manually put in some conversations...
Re: Using C# String Variable for Actor Name and During Dialogues
Sorry, I forgot about that.
After you call DialogueManager.StartConversation(), you can use this code:
If you also want to set the NPC's name:
After you call DialogueManager.StartConversation(), you can use this code:
Code: Select all
// Get a reference to the conversation we just started:
var conversation = DialogueManager.MasterDatabase.GetConversation(DialogueManager.LastConversationStarted);
// Get a reference to the current conversation model's player info:
var playerInfo = DialogueManager.ConversationModel.GetCharacterInfo(conversation.ActorID);
// Set the player info's Name:
playerInfo.Name = GV.stringPlayerName;
// Also set Variable["Actor"] so we can use [var=Actor] in Dialogue Text:
DialogueLua.SetVariable("Actor", playerName);
Code: Select all
var npcInfo = DialogueManager.ConversationModel.GetCharacterInfo(conversation.ConversantID);
npcInfo.Name = npcName;
DialogueLua.SetVariable("Conversant", npcName);
Re: Using C# String Variable for Actor Name and During Dialogues
What if most of our conversations have between 4 and 6 people talking? (see attached screenshot with 4 people talking)
None stay "actor" or "conversant" more than 1 node... they change all over the place all the time... Isnt there a way "not" to do it on runtime? and to make it work in the dialogue manager directly?
change the actor field name by some lua code or something that would always be equal to the playername string?
something "similar" to the 2nd picture i'm uploading now hehe...
None stay "actor" or "conversant" more than 1 node... they change all over the place all the time... Isnt there a way "not" to do it on runtime? and to make it work in the dialogue manager directly?
change the actor field name by some lua code or something that would always be equal to the playername string?
something "similar" to the 2nd picture i'm uploading now hehe...
Re: Using C# String Variable for Actor Name and During Dialogues
I'll look into supporting this in version 1.7.1, which I expect to release by the end of the weekend. I'm thinking of adding a Display Name field, similar to what quests support. You'll be able to set the Display Name field to [var=GV.stringPlayerName].
Re: Using C# String Variable for Actor Name and During Dialogues
OMG WOW... that is.... i'm beyond words now...
That would indeed be the most easy way to pull off something like that
I still have plenty to do so don't strain yourself working overtime for this... even if it takes another week its fine
Now i'll only need to figure out the last part... how to display "GV.stringPlayerName" inside a dialogue node... that should be pretty easy... lol...
Thanks for all your amazing work!
That would indeed be the most easy way to pull off something like that
I still have plenty to do so don't strain yourself working overtime for this... even if it takes another week its fine
Now i'll only need to figure out the last part... how to display "GV.stringPlayerName" inside a dialogue node... that should be pretty easy... lol...
Thanks for all your amazing work!
Re: Using C# String Variable for Actor Name and During Dialogues
No problem. Thanks for giving me the idea for this feature. It's implemented and available right now in 1.7.1beta2 on the Pixel Crushers customer download site. When importing any package, remember to back up your project before importing, just to be safe.
In the Dialogue Editor, inspect the Player actor and tick Use Display Name. Then in the Display Name field enter:
Inside your dialogue nodes, use the same tag in your Dialogue Text. For example:
In the Dialogue Editor, inspect the Player actor and tick Use Display Name. Then in the Display Name field enter:
Code: Select all
[var=GV.stringPlayerName]
- Dialogue Text: "Pretty good, [var=GV.stringPlayerName]! Ready to up the ante?"
Re: Using C# String Variable for Actor Name and During Dialogues
OMG WOW you are so amazing!!! so fast!!!
There is however a small issue...
I checked the "use display name" and entered [var=GV.stringPlayerName] in that box... and i tried it in one of the conversations as well...
When in the game, the player character returned "nil"
and when it arrived at the line containing [var=GV.stringPlayerName], it also wrote "nil" and stopped writing the following text that was after that...
There is however a small issue...
I checked the "use display name" and entered [var=GV.stringPlayerName] in that box... and i tried it in one of the conversations as well...
When in the game, the player character returned "nil"
and when it arrived at the line containing [var=GV.stringPlayerName], it also wrote "nil" and stopped writing the following text that was after that...
Re: Using C# String Variable for Actor Name and During Dialogues
Is "GV.stringPlayerName" defined as a variable in the Variables section of the Dialogue Editor?
If I misunderstood and "GV.stringPlayerName" is a variable in your C# script, you can set a corresponding Dialogue System variable with this line of C#:
If I misunderstood and "GV.stringPlayerName" is a variable in your C# script, you can set a corresponding Dialogue System variable with this line of C#:
Code: Select all
using PixelCrushers.DialogueSystem;
...
DialogueLua.SetVariable("GV.stringPlayerName", GV.stringPlayerName);