Namespaces and numbers conversion problem...
by Manjit Bedi · in Torque Game Builder · 12/15/2007 (2:34 pm) · 3 replies
I have implemented a basic GUI for setting some global settings in a game. I am using TGB v 1.3.1 in a Mac. I based some of my work on the very helpful example making an options gui.
http://tdn.garagegames.com/wiki/TGB/MiniTuturials/GUIOptionsMenu
Here is some code, a bit sloppy but it works, for getting a value from a text edit control and storing the value:
This appears to be fine.
I then write the globals object to a text file:
But when I look at the text file for globals.cs the value have been converted to strings. I want to keep them as numbers. Other items in the globals name space are staying as number; these items are not currently used at run-time.
I can when loading the file convert the string back to a number if I really have to.
http://tdn.garagegames.com/wiki/TGB/MiniTuturials/GUIOptionsMenu
Here is some code, a bit sloppy but it works, for getting a value from a text edit control and storing the value:
%str = %jumpVelocityCtrl.getValue(); $gPlayerJumpVeloctiy = firstWord(%str); %str = %gravitySettngCtrl.getValue(); $ConstantForceY = firstWord(%str); $globals::playerJumpVeloity = $gPlayerJumpVeloctiy; $globals::gravity = $ConstantForceY;
This appears to be fine.
I then write the globals object to a text file:
// export these prefs to our globals prefs file
export("$globals::*", "~/data/files/globals.cs");But when I look at the text file for globals.cs the value have been converted to strings. I want to keep them as numbers. Other items in the globals name space are staying as number; these items are not currently used at run-time.
I can when loading the file convert the string back to a number if I really have to.
$globals::castle_strobe_time = 5000; $globals::count_start_player_idle = 15; $globals::count_walk_to_run = 1; $globals::gravity = "150"; $globals::playerJumpVeloity = "-40";
About the author
Been making mobile iOS apps mostly in UI Kit. Been doing a few game related projects more recently.
#2
I am using the wrong functions then? I was working under the assumption that the getValue call will return a string.
So I should something other than firstWord to get the value out. What might the function be? I have had a look through the documentation.
Thanks.
M
12/16/2007 (2:04 pm)
Oh ok.I am using the wrong functions then? I was working under the assumption that the getValue call will return a string.
So I should something other than firstWord to get the value out. What might the function be? I have had a look through the documentation.
Thanks.
M
#3
12/17/2007 (4:17 pm)
In TorqueScript, everything is a string. For instance, "123" - 3 = 120 = "120". Just treat them as numbers and it should work fine, no conversion necessary.
Chaim Krause
Chaim Gang
They are not being converted to strings, they *are* strings. Look at your code. You're using string functions.