How do I make GUI text that is dynamic?

Started by lakotajames, Tue 16/09/2008 18:41:20

Previous topic - Next topic

lakotajames

I want to make text on a GUI display the contents of a string or variable.  How can I do that?

Khris

Using a label.

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

And RTFM ;)

lakotajames

Thanks.  I only read the section under "other features", I didn't think to check in the scripting section  :-[

Khris

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. :)

keyes

Is there any way to do this with using the global variables from the global var editor.

Makeout Patrol

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.

keyes

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

Khris

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.
You won't need a variable in this case.

Just add a custom property (type: String, name: "location", default value: "") and enter the location's name for every room.

Add this to GlobalScript.asc:
Code: ags
function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) labelname.Text = Room.GetTextProperty("location");
}


lakotajames

"Error: (line 42) Undefined token 'labelname'"

This wouldn't have to do with me using 2.72, would it?

Lt. Smash

of course you have to change 'labelname' to the name of your label  ::)

Mazoliin

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

SMF spam blocked by CleanTalk