Hi,
I have just started playing with AGS. I checked the manuals and watched all the videos, and I can't find the answer.
How do I call a variable inside the text of a GUI? I want to display the name of the planet you are on in the status bar. I have a variable called PlanetName, but how do I get it there? I got it to display the score by using @SCORE@, buy how can I use my own variables?
Thanks.
I'm talking about labels, not text boxes that ask for user input, btw.
Add the variable in the Global Variables section and you can reference it from anywhere, however it wont automatically update a label on a GUI.
What I would do is create a function that sets the global variable and updates the label on the GUI, then anytime the planet name needs to change call the function instead of just setting the variable.
Not sure which part exactly was causing trouble, but since nobody mentioned this yet -
You can set any text by using Label's Text property:
lblMyLabel.Text = PlanetName;
if you need to put non-string variable, like integer, the conversion is done usually using String.Format function, for example:
lblMyLabel.Text = String.Format("%d", myNumber);
Where to put these commands depend on situation. The simpliest way is to put them into repeatedly_execute in the GlobalScript.asc, and that would ensure that your label is updated every game tick. If you do not need to do this that often (or feel the need to optimize your script a bit), then you can follow dayowlron's suggestion, and create a function that both sets variable and updates labels, something like
function SetPlanetName(String new_name)
{
PlanetName = new_name;
lblMyLabel.Text = PlanetName;
}
That's got it!
Thank you so much. I was focussed on the place to enter the text and didn't think to call the name of the label.
Much appreciated!