- Home /
Dialogue & GUI Text String
Hi all! I've been trying to create a simple, easy dialogue system using only one GUIText. So far, this is all I have, but it only displays the last string element typed. Is there a way to have multiple lines, or a line for each element string? Thanks for the help in advance! :D
var dialogue = false;
var Text : GUIText;
var dialogLines : String;
function Start(){
if(dialogue){
for(var item : String in dialogLines){
Text.text = item;
}
}
Answer by KrisSchnee · Apr 03, 2014 at 09:28 PM
What I'd do is create a list of lines, then cycle through them. In pseudocode:
lines as (string, 10)
def AddLine(text):
for i in range(1,9):
lines[i-1] = lines[i]
lines[-1] = text
This way you're replacing the contents of lines[0] with the contents of lines[1], which deletes the old lines[0], then moving lines[2] up to 1, and so on, and finally putting the new text into the last slot, #9. If you're then wanting to put all of that text into a single paragraph you could do a string join operation, something like " ".join(lines).
By the way, my limited understanding is that GUIText does not have built-in line wrapping, while the GUI.Box function does (if the GUI style has a checkbox marked for that), so you might want to use GUI.Box instead. I'd like to get a system in place where I can easily say "pop up a box that has this auto-word-wrapped text, then let me know when the user's hit Enter or something to clear it". Please provide a link if you end up producing a good system you'd like to share!
Yeah, GUIText doesn't have text wrapping, so I decided to display one line at a time using indexes. The code seems flawless, if there's such a thing as flawless code, but now it doesn't show anything at all! Any help would be appreciated! :)
var dialogue = false;
var Text : GUIText;
var dialogLines : String[];
var displayIndex = 0;
private var dialogToggle = true;
function Update(){
if(dialogue){
Text.text = dialogLines[displayIndex];
}
if(dialogue && dialogToggle && Input.Get$$anonymous$$ey("return")){
NextLine();
}
if(displayIndex > dialogLines.length){
audio.PlayOneShot(confirm);
Node();
Destroy(gameObject);
}
}
function NextLine(){
displayIndex++;
dialogToggle = false;
yield WaitForSeconds(1);
dialogToggle = true;
}
One problem might be "Input.Get$$anonymous$$ey", which should fire every animation frame Enter is held down, rapidly flipping through lines. So I'd change that to Input.Get$$anonymous$$eyDown.
Your answer
Follow this Question
Related Questions
Execute String as Code Line? 1 Answer
How do I find font by passing a string? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
GuiText Problem 1 Answer
Check if a guiText = a number? 2 Answers