Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: idiotbox on Thu 14/07/2005 22:31:04

Title: Displaying Health Ints
Post by: idiotbox on Thu 14/07/2005 22:31:04
On my GUI, I want my health int to be displayed. I know you use labels, and I've been looking at the manual but the examples don't seem to be close to what I want. Can anyone give me some pointers?
Title: Re: Displaying Health Ints
Post by: DoorKnobHandle on Thu 14/07/2005 22:36:16
Well, you have your integer variable in your global script file and then in your repeatedly_execute function you add something like this:



if ( IsGUIOn ( MY_GUI ) == 1 )
   SetLabelText ( MY_GUI, MY_LABELNR, MY_VAR );



This first checks if your GUI named MY_GUI in this example is turned on (ie: is visible at the moment) and then if it is visible it sends your var named MY_VAR here to the label on your GUI. You'd need to replace MY_GUI with the number or name of the GUI you have your label on, MY_LABELNR with the object number of your label and MY_VAR with your integer variable...

Hope this helps and by the way I didn't not check that code in ANY way, just wrote it without even having AGS opened, so there might be an error in it.
Title: Re: Displaying Health Ints
Post by: idiotbox on Thu 14/07/2005 22:53:11
Yes, neither of them can be defined. All the new codes replaced them now I suppose. I can't seem to find the new way of checking if a GUI is on.
Title: Re: Displaying Health Ints
Post by: strazer on Thu 14/07/2005 22:57:35
In AGS v2.7, you can check if a GUI is enabled with the GUI.Visible property:


  if(gMy_gui.Visible == true) {


Quoteand MY_VAR with your integer variable...

Since labels can only display text strings, you have to convert your integer to a string first:


   string tempstr;
   StrFormat(tempstr, "%d", MY_VAR);
   SetLabelText ( MY_GUI, MY_LABELNR, tempstr);


In AGS v2.7, you give the label a name in the editor and just do
  mylabelname.SetText(tempstr);

-

If you're using a GlobalInt to store your health, you could also just set the label's text to @GIx@ where x is the number of the GlobalInt.
Title: Re: Displaying Health Ints
Post by: DoorKnobHandle on Thu 14/07/2005 23:05:19
Aww, thanks for correcting me there, strazer.

This stuff happens when you answer without trying out anything when you're actually to newb to answer without trying out... ;)
Title: Re: Displaying Health Ints
Post by: idiotbox on Thu 14/07/2005 23:09:30
Thanks a lot guys. It worked!