Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: lakotajames on Tue 16/09/2008 18:41:20

Title: How do I make GUI text that is dynamic?
Post by: lakotajames on Tue 16/09/2008 18:41:20
I want to make text on a GUI display the contents of a string or variable.  How can I do that?
Title: Re: How do I make GUI text that is dynamic?
Post by: Khris on Tue 16/09/2008 19:33:38
Using a label (http://www.adventuregamestudio.co.uk/manual/GUI%20Label%20functions%20and%20properties.htm).

labelname.Text = String.Format("%d", health_points);    // integer
labelname.Text = player_name;         // string

And RTFM ;)
Title: Re: How do I make GUI text that is dynamic?
Post by: lakotajames on Wed 17/09/2008 18:00:57
Thanks.  I only read the section under "other features", I didn't think to check in the scripting section  :-[
Title: Re: How do I make GUI text that is dynamic?
Post by: Khris on Wed 17/09/2008 18:14:36
There are loads of problems not explained in the tutorial.
Most of the easy ones can be solved by browsing through the scripting section or using the forum search.
It's also possible to do a full text search of the manual.

I didn't want to be rude, but if people ask questions here that are plainly answered in the manual, they get a RTFM. :)
Title: Re: How do I make GUI text that is dynamic?
Post by: keyes on Wed 17/09/2008 20:52:49
Is there any way to do this with using the global variables from the global var editor.
Title: Re: How do I make GUI text that is dynamic?
Post by: Makeout Patrol on Wed 17/09/2008 22:34:13
Quote from: keyes on Wed 17/09/2008 20:52:49
Is there any way to do this with using the global variables from the global var editor.

Sure. You create a string variable in the global variable editor, and set the label to the value of the global variable, like this, whenever you want the label text changed:

lblLabel = vGlobalString;

This, however, is absurd and stupid, because you now have two variables representing the exact same thing. There's really no reason to do this, as you can set the text of the label from any script and save yourself a bunch of time.
Title: Re: How do I make GUI text that is dynamic?
Post by: keyes on Wed 17/09/2008 22:42:54
Well I was wondering if you can put something in the text box for the label that will refer to one of my global var. 
ex. my var states the location.
I have a gui with a label to state my location at all times.  what do i enter into the text that makes it state my variable
Title: Re: How do I make GUI text that is dynamic?
Post by: Khris on Wed 17/09/2008 23:16:27
You can't do that; you have to do it manually.
If the label's text is gonna change at every room change, it's best to use the global script's on_event function (http://www.adventuregamestudio.co.uk/manual/TextScriptEvents.htm).
You won't need a variable in this case.

Just add a custom property (http://www.adventuregamestudio.co.uk/manual/Custom%20Properties.htm) (type: String, name: "location", default value: "") and enter the location's name for every room.

Add this to GlobalScript.asc:
function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) labelname.Text = Room.GetTextProperty("location");
}
Title: Re: How do I make GUI text that is dynamic?
Post by: keyes on Wed 17/09/2008 23:56:58
oh, ok thanks for the help
Title: Re: How do I make GUI text that is dynamic?
Post by: lakotajames on Fri 19/09/2008 18:24:10
"Error: (line 42) Undefined token 'labelname'"

This wouldn't have to do with me using 2.72, would it?
Title: Re: How do I make GUI text that is dynamic?
Post by: Lt. Smash on Fri 19/09/2008 18:36:26
of course you have to change 'labelname' to the name of your label  ::)
Title: Re: How do I make GUI text that is dynamic?
Post by: Mazoliin on Fri 19/09/2008 18:37:12
If you just copied the code, then you need to re-name "labelname" to the actual name of the label you're using.

[Edit]
Beaten by Smash