Game Development Community

Displaying value of variable in a GUI

by Jacob · in Game Design and Creative Issues · 01/17/2005 (8:00 pm) · 13 replies

I would appreciate some help on displaying my character's stats (RPG type) in a GUI. I have all my variables set up and I tried using different GUI controls to display these variables but haven't come upon the right way to do it yet. So far I have used GUITextEditCtrl with a command: echo($MyVariable); and also tried to put $MyVariable in the variable field - didn't work. Also, in this case I don't want the user to be able to edit the variable, it just needs to be displayed - so GUITextEditCtrl is probably not the way to go, right?

#1
01/17/2005 (8:09 pm)
Echo() sends the information to the console. What you can do is use a GuiTextCtrl, and then use ctrlName.setText($MyVariable), or ctrlName.text = $MyVariable.
#2
01/17/2005 (8:14 pm)
Thank you for the fast 9 minute response! :)
#3
01/17/2005 (9:01 pm)
Hmm...I tried and tried but didn't get it to work.

I tried giving the commands above in the GUI file so it loads automatically and also in the "command" field right in the GUI Editor - using a GUITextCtrl. Is it too much to ask to show me step by step how to get this to work...making a VERY simple GUI and all? :)
#4
01/18/2005 (9:48 am)
Well, it actually did work but not completely - I still have to press apply in the GUI editor to have the value show up.

Is there any way to have it apply in script?
#5
01/18/2005 (11:13 am)
Ok, someone on IRC helped me get the result I was looking for: use a GuiTextCtrl, under variable put $MyVariable and whenever $MyVariable is updated, the GuiTextCtrl will keep up with it! Tried it and it works.
#6
02/28/2005 (3:58 pm)
I've been trying something similar to this. I'm trying to get an interactive menu going, where when you select items off one drop down menu, your resource reserves in a guiTextEditControl deplete. It works just like I want it to except for one thing: The player can just click back into the GuiTextEditControl box and change the resource number to whatever they want it to be. (As In: "Hm... let's buy a ton of stuff... and then give myself a million dollars back. Cool.")

I don't see an existing way to make a GuiTextEditControl uneditable. Have I missed something, or is it subclassing time? (From what I see, I could make a subclass uneditable just by crippling its onMouseDown() methods and their ilk.)
#7
02/28/2005 (7:10 pm)
A GuiTextCtrl is un-editable...(that is one can't just click the mouse in it and change something) is that what you are looking for? It will work the same but will not show up in a box though, like the GuiTextEditCtrl.
#8
02/28/2005 (9:46 pm)
Indeed. That works. I'll just put a bitmap behind it to make it stand out.
#9
03/23/2005 (8:09 pm)
Gents: I tried to follow this and implement it as a way to show remaining ammo for the crossbow in the fps demo, but no dice. Any chance you could put it in step-by-step instructions? Thanks.
#10
03/23/2005 (8:22 pm)
@Richard: The ammo is probably stored in a variable so all one would have to do is to put that variable in the "variable" field in a GuiTextCtrl and it will update whenever the variable changes. For example: variable = $AmmoLeft; (or the correct variable name linked to the ammo in question).
#11
03/24/2005 (9:11 am)
Jacob: That's what I was thinking, too. I opened playGui in the GUI editor and added a new control of the GuiTextCtrl type. I filled in the variable field with "%currentAmmo" (without quotes and no semi-colon at the end), this variable name seeming to be the one indicated in the script file for the crossbow. I named the control, and added "Ammo:" in the text field of the gui. I didn't put anything in the command field, or anywhere else. Finally, I saved the playGui and exited the GUI editor. The "Ammo:" text showed up, but nothing else. So, if this seems correct, then the only thing I can think of is that I've got the variable name wrong. That's entirely possible, as it was hard for me to pick out which variable was the ammo count. There were no errors reported in the console. Oh, and I tried to type in "echo(%currentAmmo);" in the console, but it didn't echo anything back. That's why I'm thinking this is the wrong variable name, assuming I did everything else correctly.
#12
03/24/2005 (4:38 pm)
When you use "%" in front of the variable, it indicates a local variable (valid only in the scope of the function it is used). In the function where %currentAmmo is in, type the following $AVariableNameYouLike = %currentAmmo; Make sure this goes somewhere after %currentAmmo is initialized (a value assigned to it) "$" in front of the variable indicates a global variable, valid (available) in the whole program. You may want to ckeck this part of the Torque General Documentation for any other info on scripting. Have fun! :)
#13
03/29/2005 (9:35 am)
Jacob: Thanks, I'll try that. Got side-tracked by other issues, but I'll give this a whirl when I get home tonight.