Game Development Community

Cannot create t2dTextObjects from script

by Dustin Sims · in Torque Game Builder · 12/21/2006 (9:58 pm) · 2 replies

I am having a problem creating new textobjects..
I want to create an "array" of Textobjects on the screen to use mainly for debugging purposes..
I was going to update their text fields so that I could watch the contents of another real array.

The problem is that when I use this code, the textobjects never appear.
The code is running because I can see the echo that I used inside the Loops.
I cut and pasted the new t2dTextobject code from the Level.t2D file.

I am a little confused on how TGB sets the fields and why it always uses "strings" as the values for it's fields.. Will using this -- position = %positionstring; Work for me...

I also just tried to set it's position using the setposition after the object was created.
Am I just doing something wrong here.

for (%r = 0; %r< 10;%r++)
   {
      for (%c = 0; %c < 12;%c++)
      {
   %tempRowPos = -225 + (%r * 50);
   %tempColPos = 275 - (%c * 50);
   %postionstring = %tempRowPos @ " " @ %tempColPos;
   echo(%postionstring);                  
   %tempName = %r @ "_" @ %c;
   
   %temptext = new t2dTextObject(%tempName) {
      canSaveDynamicFields = "1";
      size = "34.000 20.000";
      position = %positionstring;
      text = "9999";
      font = "Arial";
      wordWrap = "0";
      hideOverflow = "1";
      textAlign = "Left";
      lineHeight = "20";
      aspectRatio = "1";
      lineSpacing = "0";
      characterSpacing = "0";
      autoSize = "1";
      fontSizes = "10";
      textColor = "1 1 1 1";
         hideOverlap = "0";
         mountID = "5";
   };
   
   %temptext.setposition(%tempRowPos,%tempColPos);
   
      }
   
   }



Thanks..

#1
12/22/2006 (5:50 am)
You forgot SceneGraph!

scenegraph = %this.scenegraph;

%temptext = new t2dTextObject(%tempName) {
      scenegraph = %this.scenegraph;
      canSaveDynamicFields = "1";
      canSaveDynamicFields = "1";
      size = "34.000 20.000";
      position = %positionstring;
      text = "9999";
      font = "Arial";
      wordWrap = "0";
      hideOverflow = "1";
      textAlign = "Left";
      lineHeight = "20";
      aspectRatio = "1";
      lineSpacing = "0";
      characterSpacing = "0";
      autoSize = "1";
      fontSizes = "10";
      textColor = "1 1 1 1";
         hideOverlap = "0";
         mountID = "5";
   };
#2
12/22/2006 (8:29 pm)
Thanks alot,

This helped out tremendously and etched it into my brain as I am just learning torque...
It wound up just needing scenegraph = %this
I am creating them in a Scenegraph::Function.