Print stats on a GUI
by Mitchell · in Torque Game Engine · 11/26/2006 (2:59 pm) · 8 replies
How would I print any player stats to the GUI? Say for example, print the maxForwardSpeed to any label in the gui. I can't seem to access this information from anywhere. I want the info to be displayed, and updated automaticly every frame to represted what my maxForwardSpeed will be.
#2
11/26/2006 (3:10 pm)
If you are using a gui txt label, you will need to write a schedule for it too.
#3
11/26/2006 (3:32 pm)
Ok, I get that, but how do I grab maxForwardSpeed? I don't know whow to access any information stored by the player
#4
11/27/2006 (12:39 pm)
Do the starting out tutorial .pdf it tells you exactly how to do this, except it uses the players score.
#5
I'm assuming your player is named "PlayerA"
// "Grab" PlayerA's MFS and assign it to variable %speedA
PlayerA.maxForwardSpeed = %speedA
// Echo the new variable to the console... or write any other funtion to put the variable where you want it
echo (%speedA)
Try that... and if someone sees something wrong here, please let me know so I can learn too. :)
11/27/2006 (10:24 pm)
Except the "player's score" from that tutorial isn't a field stored in the player datatblock, it's a newly declared variable that is in a seperate script from the player. Here is the way you reference fields, I think (I'm also still fairly new at this):I'm assuming your player is named "PlayerA"
// "Grab" PlayerA's MFS and assign it to variable %speedA
PlayerA.maxForwardSpeed = %speedA
// Echo the new variable to the console... or write any other funtion to put the variable where you want it
echo (%speedA)
Try that... and if someone sees something wrong here, please let me know so I can learn too. :)
#6
11/28/2006 (7:58 am)
Quote:// "Grab" PlayerA's MFS and assign it to variable %speedAI don' know about TorqueScript, but in any other programming language that would try and set PlayerA's maxForwardSpeed to %speedA. So, assuming datablock variables can be altered like that, and %speedA being equal to 0 at the time of its creation, the player's maxForwardSpeed would be set to 0. If you flip the equation (%speedA = playerA blah blah), then %speedA would contain the player's maxForwardSpeed value.
PlayerA.maxForwardSpeed = %speedA
#7
I needed something more than that and used the metrics("fps") functionality as a reference.
guiConsoleTextCtrl takes an expression that is evaluated and the resulting value is displayed as the text for the control. This is great for real-time tracking of variables or simple expressions (expressions are evaluated each frame so you don't want to do anything complex).
The expression can also be simply a variable, such as $platform, or a function call.
As an example, I'm using it to show joystick x & y coordinates in real-time.
Also updated the TDN wiki:
tdn.garagegames.com/wiki/GUI/Profiles/ControlList#GuiConsoleTextCtrl
As per the note stated, this control currently supports only 1 instance. metrics() creates 1 instance and then creates a string that concatenates everything into one line. However, this wasn't really what I wanted so I modified guiConsoleTextCtrl to keep its own string buffer (like guiTextCtrl) to support multiple instances.
I have submitted a resource to fix this, which is pending moderation by GG.
11/28/2006 (9:32 am)
If you are only tracking variables, then guiTextCtrl allows that.I needed something more than that and used the metrics("fps") functionality as a reference.
guiConsoleTextCtrl takes an expression that is evaluated and the resulting value is displayed as the text for the control. This is great for real-time tracking of variables or simple expressions (expressions are evaluated each frame so you don't want to do anything complex).
The expression can also be simply a variable, such as $platform, or a function call.
As an example, I'm using it to show joystick x & y coordinates in real-time.
Also updated the TDN wiki:
tdn.garagegames.com/wiki/GUI/Profiles/ControlList#GuiConsoleTextCtrl
As per the note stated, this control currently supports only 1 instance. metrics() creates 1 instance and then creates a string that concatenates everything into one line. However, this wasn't really what I wanted so I modified guiConsoleTextCtrl to keep its own string buffer (like guiTextCtrl) to support multiple instances.
I have submitted a resource to fix this, which is pending moderation by GG.
#8
11/28/2006 (6:06 pm)
Yes, Daniel is right about the order of assigning a value to a variable, sorry for the mistake :)
Torque Owner Stefan Lundmark