PDA

View Full Version : Problems Detecting Number String?


Omini
05-30-2006, 04:48 PM
I've tried this.

if (client.cxammo > 0) { }

and

if (client.cxammo > "0") { }

but neither work. How do I get it so it'll read it as a number? Since like that it doesn't seem to be doing it.

Skyld
05-30-2006, 04:51 PM
Hm, try echo()ing the value to check that it is what you think.

xXziroXx
05-30-2006, 05:35 PM
If its a string, makevar(client.cxammo)? I dunno, never had to use that one..

Yen
05-30-2006, 09:41 PM
Are you sure your server's GS2 enabled?

Tolnaftate2004
05-31-2006, 02:17 AM
float(string) will make it a number.

Tyrial
05-31-2006, 02:39 AM
float(string) will make it a number.

I don't know about GScript but isn't float for decimals?

ApothiX
05-31-2006, 02:51 AM
The second one shouldn't work, but the first one definitely should. You should follow Skyld's advice and echo out the contents of that variable. (Also see my reply to Tyrial for explanation of the 'strings' and 'numbers' misconception)

If its a string, makevar(client.cxammo)? I dunno, never had to use that one..
hrm no, makevar isn't what you're thinking it is. makevar takes a string and uses it's contents for the name of the variable to access.

temp.kewlstring = "Wee";
temp.varname = "temp.kewlstring";
echo(makevar(temp.varname));
Would output: Wee

jake13jake
05-31-2006, 05:09 AM
Well, stuff that is good to know in gs2:

strings values of "true" and "false" can be interpreted as booleans
var set to boolean value false will not exist.
var with value of 0 makes the var not exist.

float with value of 0 will show blank.
string with value of "0", however, makes the var still exist.
a string value that stores a number, in GS2, is automatically converted to a float value when performing math operations on it.

a sleep-iteration loop will not store temp.vars through multiple iterations

Omini
05-31-2006, 05:47 AM
Alright, thanks for your help.

Omini
05-31-2006, 06:08 AM
Are you sure your server's GS2 enabled?

Yes, I am 100% positive. I tested with this -

function onWeaponfired()
{
player.chat = "Boo!";
}

Worked - so it's obviously GS2 enabled.

Also another small problem that doesn't appear to be working properly for reasons unknown

function onKeypressed(character)
{
if (character == "s") {
if (client.cx == "on") {
putaway();
}
}
}

And yes I have a "function putaway()" occuring later in the script.

Well, stuff that is good to know in gs2:

strings values of "true" and "false" can be interpreted as booleans
var set to boolean value false will not exist.
var with value of 0 makes the var not exist.

float with value of 0 will show blank.
string with value of "0", however, makes the var still exist.
a string value that stores a number, in GS2, is automatically converted to a float value when performing math operations on it.

a sleep-iteration loop will not store temp.vars through multiple iterations

To me, all your saying is "The first one should work and I have no idea why it doesn't". But thanks for your input (of information).

Omini
05-31-2006, 07:10 AM
Uh ok it works now, heh heh. I found the problem. There was an error in the script before hand where it had

if (client.cxclip == "on") { }

instead of

if (client.cx == "on") { }

Heh.

ApothiX
05-31-2006, 02:10 PM
Well, in Skyld's mad frenzy of deleting and editing posts he deleted some actual information I had in my post. I am too lazy to retype it now, so for the "(Also see my reply to Tyrial for explanation of the 'strings' and 'numbers' misconception)" I guess you'll have to use google.

Skyld is turning into Moonie, by the looks of it.

xAndrewx
05-31-2006, 03:35 PM
function onKeypressed(character)
{
if (character == "s") {
if (client.cx == "on") {
putaway();
}
}
}

function onKeyPressed(Code, Key)
{
if (client.cs != "on")
return;
if (Key == "s")
putaway();
}
It's code, and then key :]

Skyld is only doing what is right, I guess most of the posts were pointless.

jake13jake
05-31-2006, 05:58 PM
Things that you can store as boolean values rather than strings or integers makes things run faster (ex. use client.cx = true instead of client.cx = "on"). Using bitwise operators also makes things work faster, etc. (ex. (x|y) in range) rather than x in range && y in range.

When you can, use addition instead of multiplication
ex. do
for (i=0; i<size; i+=10)
showimg(201,image,x,y);

for (i=0; i<size; i++)
showimg(201,image,x*10,y*10);

also, when possible work in powers of two.

ApothiX
06-01-2006, 01:37 AM
Skyld is only doing what is right, I guess most of the posts were pointless.They were. But he should have been more careful when editing my original post.


Things that you can store as boolean values rather than strings or integers makes things run faster (ex. use client.cx = true instead of client.cx = "on"). Using bitwise operators also makes things work faster, etc. (ex. (x|y) in range) rather than x in range && y in range.

When you can, use addition instead of multiplication
ex. do
for (i=0; i<size; i+=10)
showimg(201,image,x,y);

for (i=0; i<size; i++)
showimg(201,image,x*10,y*10);

also, when possible work in powers of two.
Let me be the first (and probably last) person to thank you for that beautifully rendered bit of pointless (and off-topic) information.

Omini
06-01-2006, 05:17 AM
ApothiX, he's trying to be helpful. True it's not related to the topic - but if you havn't realized, the problem has been solved. No problem trying to help. :P

jake13jake
06-01-2006, 11:14 PM
ApothiX, he's trying to be helpful. True it's not related to the topic - but if you havn't realized, the problem has been solved. No problem trying to help. :P
Well, it extends off-topic, but isn't entirely off-topic. It's just small useful bits of information to know, and knowing that strings convert to floats when performing math operations on them is good to know. This is probably one of the main reasons @ is used for concatenation rather than +.
I didn't touch on everything however.
One way to test that a string is being converted to a float
temp.string = "10";
temp.string.type(); //should return the num value signifying string
temp.string += 2;
temp.string.type(); //should return the num value signifying float

(Look at Script Functions : Client : TGraalVar for the num values)

Of course, when passing by value in a function, Graal already knows the datatypes that go in a function unless they're user-defined, in which case they are interpreted the same as the rest of the scripting language within the function.