TWiki
> Main
>
TextVariables
Text Variables
This is a variable used to store text.
Creating a text variable
Right click on State and select 'Add Text'.
In the properties its a good idea to change the name to something meaningful (i.e. something that describes what the variable will store like 'playerName', or 'welcomeMessage'). You can also set a default value for the variable.
Setting the value with code
Setting the value of a text variable in code is straightforward:
myTextVariable.Value = "text";
You start with the name of your text variable, add a full stop - at which point a pop-up should appear - add 'Value', then an equals sign. The text you want to store in the variable must appear between "inverted commas" and you should end the line with a semi-colon.
It's worth pointing out that
text is not just lower case and capitalised alphabetical characters, but can also include spaces, symbols and numbers. So as well as single words you can store sentences, including numbers and symbols like full stops, apostrophes and question marks. For example:
myTextVariable.Value = "Welcome! Are you number 6?";
Since inverted commas are used to wrap the text to be stored you cannot use these directly within a text variable. If you do need to include them you can use what is known as an
escape character (a backslash: \ ) in front of each inverted comma within the variable. For example:
myTextVariable.Value = "He said: \"Do you have the time?\"";
In this case the text stored is
He said: "Do you have the time?".
Accessing the value of a text variable
Simply reference the
Value property of the variable. For example to display the value of the variable in the logger:
Logger.Log(myTextVariable.Value);