Game Development Community

Change Symbol

by Tyler Slabinski · in Torque Game Builder · 07/28/2009 (7:23 am) · 5 replies

function t2dScenegraph::onLevelLoaded(%this, %scenegraph)
{
	%text = getRandomSymbol();
	
   $symbol = new t2dTextObject() {
	  scenegraph = SceneWindow2D.getSceneGraph();
      canSaveDynamicFields = "1";
      position = "-20.000 17.500";
      size = "20.000 25.000";
      FlipX = "1";
      Layer = "1";
      BlendColor = "0 0 0 1";
      text = %text;
      font = "Arial";
      wordWrap = "1";
      hideOverflow = "1";
      textAlign = "Center";
      lineHeight = "25";
      aspectRatio = "1.21809";
      lineSpacing = "0";
      characterSpacing = "0";
      autoSize = "1";
      fontSizes = "160";
      textColor = "0 0 0 1";
         mountID = "2";
   };
}

function getRandomSymbol()
{
	%symbolList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+~{[}]|;:<>?/";
	return getSubStr($symbolList, getRandom(0,strlen(%symbolList)), 1);
}

The above code is suppose to do this:

When the level loads up, get a random symbol from the list %symbolList and make the text object display that symbol.

Anyone know what's wrong with this? It doesn't seem to be doing anything. It doesn't show any error, and yes I have executed it.

#1
07/28/2009 (8:11 am)
Heya Tyler... Something like this... untested.

$symbolList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+~{[}]|;:<>?/";

function getRandomSymbol()
{
   %symbolIndex = getRandom(0,strlen($symbolList));
   return getSubStr($symbolList, %symbolIndex, 1);
}
#2
07/28/2009 (12:10 pm)
Tested it in the console, and it works like a charm!

That saved me the trouble of having a couple dozen switch statements...
#3
07/28/2009 (12:34 pm)
Cool! you should church it up and use it like this though... :)
function getRandomSymbol()
{
   %symbolList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+~{[}]|;:<>?/";

   return getSubStr($symbolList, getRandom(0,strlen(%symbolList)), 1);
}
#4
07/28/2009 (5:03 pm)
I changed the subject. Can anyone help with this?