Game Development Community

A stats screen?

by Mehmet Emre Yorulmaz · in Torque 2D Beginner · 02/03/2015 (6:45 am) · 8 replies

Is there any way to output text on the screen?
For eg, a screen that displays the amount of mouse clicks on the screen and saves it for later play sessions with the use of taml read and write.

#1
02/03/2015 (5:56 pm)
You have an entire GUI system for putting stuff on the screen.

You can also use ImageFont objects, I believe, for in-scene text if you don't want a text box or some such blocking mouse events from entering the edge of your scene. Might be wrong on this one. You can always look at the ImageFontToy in the sandbox.
#2
02/04/2015 (4:20 am)
I have checked out the Imagefont toy when i first thought about this.
But would it be possible to implement such a system the same way the GUI is implemented?
Maybe something like the bluebuttons but without the button part, i tried to implement this with the use of the "GuiSolidProfile" which adds a "solid" grey background on the text making it easier to see,But its still essentially a button,Would it also be possible to align the text? Since the GUI is defined in the gui.taml files and those files work with XML, i don't think torque script would work if i tried to add new lines on the text.
#3
02/04/2015 (6:14 am)
What are you trying to accomplish? Is there a reason you can't just use a GUI?
Quote:
Since the GUI is defined in the gui.taml files and those files work with XML, i don't think torque script would work if i tried to add new lines on the text.
What do you mean? If you add GUI objects in the gui.taml file they will load just like all of the other objects in the gui.taml file....

You can have any scene object respond to mouse events, but do you need them to? And if you use scene objects like ImageFont then you have to handle what to do if your camera moves because they're in the scene like everything else.

Besides, you can use T3D's GUI editor to prototype your GUI, then convert it to TAML for T2D:
// button in script
      new GuiButtonCtrl() {
         canSaveDynamicFields = "0";
         Enabled = "1";
         isContainer = "0";
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "top";
         Position = "216 289";
         Extent = "90 23";
         MinExtent = "8 8";
         canSave = "1";
         isDecoy = "0";
         Visible = "1";
         Command = "JoinServerDlg.query();";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         text = "Query Master";
         groupNum = "-1";
         buttonType = "PushButton";
         useMouseEvents = "0";
      };

// button in TAML
    <GuiButtonCtrl
        Name="ManipulationModeButton"
        Profile="BlueButtonProfile"
	    Text="Mode"
	    ButtonType="PushButton"
        command="cycleManipulation(true);"
        canSaveDynamicFields="0"
        isContainer="0"
        HorizSizing="left"
        VertSizing="bottom"
        Position="360 0"
        Extent="100 30"
        MinExtent="8 2"
        canSave="1"
        Visible="1"
        Active="1"
        hovertime="1000"
        groupNum="-1"
        useMouseEvents="1" />
Notice that they're the same data, just different formatting....
#4
02/04/2015 (6:45 am)
I'am really sorry,my explanation was very vague.
The exact thing i want to do is to display text on the screen,and make it stay on the screen.
The reason i want to do this is because i want to make a stats screen,which might record the amount of mouse clicks and save them to a taml file.

I attempted to accomplish this task by using this;
"
<GuiSpriteCtrl
Name="StatsDialog"
Profile="GuiToolboxProfile"
HorizSizing="relative"
VertSizing="relative"
Position="0 0"
Extent="1024 768"
MinExtent="320 320"
Visible="1"
Image="@asset=ToyAssets:skyBackground">

<!-- Main Menu-->
<GuiButtonCtrl
Name="MainMenuButton2"
Profile="BlueButtonProfile"
Text="Main Menu"
ButtonType="PushButton"
canSaveDynamicFields="0"
isContainer="0"
HorizSizing="relative"
VertSizing="relative"
Position="0 0"
Extent="200 30"
MinExtent="100 15"
canSave="1"
Visible="1"
Active="1"
hovertime="1000"
groupNum="-1"
useMouseEvents="1" />
<!-- Intro-->
<GuiButtonCtrl
Name="Intro"
Profile="GuiSolidProfile"
Text=" Welcome to the Stats menu!"
canSaveDynamicFields="0"
isContainer="0"
HorizSizing="relative"
VertSizing="relative"
Position="10 50"
Extent="200 200"
MinExtent="100 15"
canSave="1"
Visible="1"
Active="1"
hovertime="1000"
groupNum="-1"
useMouseEvents="1" />

</GuiSpriteCtrl>"

After using this to create the basics of the menu i wanted to create text boxes like the one named "intro" to show different variables which would store mouse clicks and etc,But when i tested this by replacing the text field with "$Ms" which did not work.
I also tried to manipulate the alignment of the text by using "\n" to add a new line which also did not work unsurprisingly.
So these were what i meant by "i don't think it would work".
I apologize again for my vague request.
So i guess my question is this,How do i display text on the screen without using imagefont since that sounds intimidating and also how do i manipulate that text?
Thank you for your detailed answer and time.
#5
02/04/2015 (8:08 am)
Oh, yeah, for multi-line text you need to either use another text control or a GuiMLText control (markup language, so you can include hyperlinks and colors but it also supports newlines in the text).

Okay, you are on the right track, and you can even use TamlWrite() to save your GUI object with the current values intact.

If you want a control's Text field to reflect a given global variable then assign the Variable field:
<GuiTextCtrl
   ...
   variable = $MyGlobalVariable
   ... />
Then, update that global variable with your statistic and it will automatically update in the control.
// mouse has been clicked, so
$MyGlobalVariable++; // increment click count, and it is automatically updated in GUI
#6
02/04/2015 (9:47 am)
Ok,i understand how to display variables now.
And after googling for an hour or two i kinda know how to use the Multi line text functionality too.
I had a problem with this though since the taml file does not accept "NL" and instead needs "<br>" to form a new line.
This was a bit confusing at first but i think i understand now.
My final question is what other tags can i use in this format?
#7
02/04/2015 (12:46 pm)
I don't really have a good answer for that one either... have to look in the source in gui/guiMLTextCtrl.cc/.h to find what tags were implemented. This should really be documented somewhere....
#8
02/05/2015 (3:22 am)
I agree Il check it out.