- Home /
string problem
I am doing dialogues for RPG. These dialogues are stored in String arrays.
To simply the question:
var name:string="Lucy";
var dialogue:string;
print("hello Lucy");
print(dialogue);
I want above to display same output. The problem is I don't initialize it by dialogue="hello" +Lucy; in script. Instead, I need give the value in Inspector, if I give dialogue the value: "hello" +dialogue The print output will simply be the same "hello" +dialogue not hello Lucy
How to achieve this?
Add: I am using this dialogue system made by others: http://kimmonsdesign.com/node/21
For those who don't know about it, it is a useful tool to make dialogues in game. (It can also do conversations similar to Mass Effect) The only problem is the dialogue content is fixed (defined in string arrays). And I am trying to find a way to allow it to be dynamic, that can take variables and affect the dialogue content.
(Btw, this new UnityAnswers is really buggy n poor quality. I miss the one before...oh. it was so perfect)
Answer by GlennHeckman · May 27, 2011 at 02:37 AM
Your phrasing of the question is odd. For starters, your variable types should be like this (Capital "S" in the variable type declaration):
var name:String = "Lucy";
var dialogue:String;
function Start()
{
print(dialogue + name);
// Should give you "whateverYouTypeInTheInspector Lucy"
}
It's not a beginner's question. If you ever doing dialogues for a PRG. You will understand what I mean.
Perhaps if your question and title were more clear, I wouldn't have mistaken it for a "beginners question".
You are right. And due to my experience, title that looks simpler will attract more people to click in and read the questions. lol
Answer by aldonaletto · May 27, 2011 at 02:40 AM
If you're trying to put an expression in the Inspector field, it will not work! Use expressions in the code instead:
print(dialogue+" "+name)
This way you can define the name and the phrase separetelly in the Inspector. And I agree: this new UnitAnswers sucks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612090235im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
NPC dialogue - Loading a text file to a string? 1 Answer
How to parse "tags" in strings? 1 Answer
How to transform a string into a variable in a dialogue 2 Answers
Execute String as Code Line? 1 Answer
String.Remove not working 1 Answer