int to string?
by Dawid Zwiewka · in General Discussion · 10/16/2009 (3:56 pm) · 7 replies
Hi!
I want to show points in my game. I thought that i can do this simple like that:
I can do this with loop like this:
Is there any function for adding a string to string?
Every function for that I know in string class in C++ but i don't know does it exist in tgb?
I want to show points in my game. I thought that i can do this simple like that:
%points = 15; $SomeT2DtextObject = %points;But it doesn't works of course. Is there any function which can convert Int to string? Or maybe there is a better way to show integer on the scene (with my own font)?
I can do this with loop like this:
//just a fragment
for(%i = 10; %i >= 0; %i++)
{
%temp = mFloor(%points / (10^%i));
switch(%temp)
{
case 0:
$SomeTextObject[%i] = "0";
case 1:
$SomeTextObject[%i] = "1";
//etc
}
%points /= 10;
}
//that code was written fast, so there can be some errors but i think it can be understoodBut it can be quite slow and I think unnecessary.Is there any function for adding a string to string?
%string = "a"; %string += "b"; //now %string is "ab" //i know it doesn't work but is there any function to do that? //or... %string1 = "a"; %string2 = "b"; %string3 = %string1 + %string2;
Every function for that I know in string class in C++ but i don't know does it exist in tgb?
About the author
I'm not from UK/USA so I'm sorry in advance for all grammatical mistakes :)
#2
it works, but what about my second question? I'd like to have points like that:
00000015
not just 15
is that possible to do something like:
Why T2DTextObject cannot be $global? What if i do that:
10/16/2009 (5:37 pm)
thanks, I forgot about that, I didn't use textObject before ;)it works, but what about my second question? I'd like to have points like that:
00000015
not just 15
is that possible to do something like:
SomeTextObj.text = "00000" + %points;it's just a fragment of code, I would use some loop to add as many "0" as I need (if %points == 153 for example it would be one "0" less)
Why T2DTextObject cannot be $global? What if i do that:
$MyText = %this; //that would be inside onLevelLoaded functionI think it should works correctly.
#3
10/17/2009 (12:48 am)
%first = "sand";
%second = "wich";
%third = %first @ %second;
if(%third !$= "sandwich")
echo("Well, stuff me with cotton and call me Humphrey!");Hopefully that's a little hint as to how concatenation can be done in Torque. Instead of @, which just adds the strings, you can use SPC, which adds a space between them, TAB, which adds a tab, and probably a few others which I can't remember. See for some helpful hints.Quote:Why T2DTextObject cannot be $global? What if i do that:The code you posted should work, I think.
#4
I have another question. Is there any function to heighten integer? Like in c++
I don't need to heighten float but I'd like to know if there's also function for float.
One more question.
I try to make class for my Text Objects. I wrote that:
My text object is also white not red and i don't know why.
10/17/2009 (5:36 am)
Thanks a lot!I have another question. Is there any function to heighten integer? Like in c++
pow(2.0, 5.0)Operator ^ is Bitwise XOR.
I don't need to heighten float but I'd like to know if there's also function for float.
One more question.
I try to make class for my Text Objects. I wrote that:
$GemArray[%i,%j].TextPoints = new t2dTextObject()
{
scenegraph = sceneWindow2D.getSceneGraph();
font = "Times New Roman";
Class = "GemsPoints";
size = "20 20";
textColor = "255 0 0 255";
textAlign = "Center";
aspectRatio = "1";
autoSize = "1";
fontSizes = "20";
};And function GemsPoints::onLevelLoaded(%this,%scenegraph) doesn't work because my new text isn't in that class :( Why? If i set class with function after making new text object, function onLevelLoaded will not work.My text object is also white not red and i don't know why.
#5
10/17/2009 (11:00 am)
I think you should take a look at the scripting docs. They'll give you a good overview of how the scripting works and the syntaxes involved. As a heads up, there's no strict data typing in TorqueScript, but the docs cover that. It's located in Support > Documentation.
#6
Maybe I'm looking at wrong doc?
I'm using that documentation:
http://tdn.garagegames.com/wiki/Torque_2D/Reference_Guide
http://docs.garagegames.com/tgb/official/
and also that from TGB help->documentation and searching on forum
But in documentation there is not much about string's, only few functions (all for changing font as I remember) and list of fields but without good explanation how that fields works and how to change them.
I always write on forum only if I spend few hours on searching and i can't find answer.
10/17/2009 (11:54 am)
I know. I always first look at documentation but i can't find answer for that questions :(Maybe I'm looking at wrong doc?
I'm using that documentation:
http://tdn.garagegames.com/wiki/Torque_2D/Reference_Guide
http://docs.garagegames.com/tgb/official/
and also that from TGB help->documentation and searching on forum
But in documentation there is not much about string's, only few functions (all for changing font as I remember) and list of fields but without good explanation how that fields works and how to change them.
I always write on forum only if I spend few hours on searching and i can't find answer.
#7
10/17/2009 (5:53 pm)
mPow().
Torque 3D Owner Ted Southard
A T2DTextObject is not the text itself, but the object that holds the text (in the .text field). Hope that helps.
Edit: A T2DTextObject also cannot be referenced as a $global (unless you're going to use the $global to build a string or something), so I took that out.