convert string to integer
by Louis Marchant · in Torque 3D Beginner · 10/23/2012 (10:24 am) · 5 replies
basically, i have a line of code as follows :
where $variableA1 is always an integer
and numericalMoneyHUD is always a numerical value also, albeit stored as text because it's a GUI control
if(numericalMoneyHUD.text >= $variableA1)
now this doesnt work, i can only assume because i need to convert the *.text to an integer, have checked the docs and can't find anything.
solution much appreciated, thanks :)
where $variableA1 is always an integer
and numericalMoneyHUD is always a numerical value also, albeit stored as text because it's a GUI control
if(numericalMoneyHUD.text >= $variableA1)
now this doesnt work, i can only assume because i need to convert the *.text to an integer, have checked the docs and can't find anything.
solution much appreciated, thanks :)
About the author
#2
$variableTemp1 = numericalMoneyHUD.text;
if( $variableTemp1 >= $variableA1 )
doSomething();
10/23/2012 (2:12 pm)
Might want to try:$variableTemp1 = numericalMoneyHUD.text;
if( $variableTemp1 >= $variableA1 )
doSomething();
#4
I'm sure this is the solution, however you should check teh validity of your data when errors like this occur, the other side effect of torquescript is it makes assumptions and we all know what assumptions are.
I often uses messageboxes to throw out data to the screen as i'm working, just to see whats going on.
10/24/2012 (7:29 am)
i'm pretty sure guicontrol.text doesnt work, you need to use guicontrol.getText().I'm sure this is the solution, however you should check teh validity of your data when errors like this occur, the other side effect of torquescript is it makes assumptions and we all know what assumptions are.
I often uses messageboxes to throw out data to the screen as i'm working, just to see whats going on.
#5
my VB days comming back to haunt me, lost habbit of using *.get*
thanks for all the responses people. i'm sure it will come in handy knowing all variables are strings too, sot hanks for that especially daniel.
10/24/2012 (8:19 am)
yea bloodknight, i just thought of that, and tried it, and yea it works with *.getTextmy VB days comming back to haunt me, lost habbit of using *.get*
thanks for all the responses people. i'm sure it will come in handy knowing all variables are strings too, sot hanks for that especially daniel.
Torque Owner Daniel Buckmaster
T3D Steering Committee
The comparison may be unexpected if you have non-numeric data in your string:
But it will work if the number's at the start of a string, apparently: