Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-30-2006, 04:48 PM
Omini Omini is offline
Millenium Owner
Join Date: Feb 2006
Location: N.Ireland
Posts: 293
Omini is on a distinguished road
Send a message via AIM to Omini Send a message via MSN to Omini Send a message via Yahoo to Omini
Problems Detecting Number String?

I've tried this.

NPC Code:
if (client.cxammo > 0) { }



and

NPC Code:
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.
__________________



Reply With Quote
  #2  
Old 05-30-2006, 04:51 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Hm, try echo()ing the value to check that it is what you think.
__________________
Skyld
Reply With Quote
  #3  
Old 05-30-2006, 05:35 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
If its a string, makevar(client.cxammo)? I dunno, never had to use that one..
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #4  
Old 05-30-2006, 09:41 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
Are you sure your server's GS2 enabled?
Reply With Quote
  #5  
Old 05-31-2006, 02:17 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
float(string) will make it a number.
Reply With Quote
  #6  
Old 05-31-2006, 02:39 AM
Tyrial Tyrial is offline
The Shiznic
Join Date: Dec 2001
Location: Sweden > Stockholm
Posts: 2,411
Tyrial is an unknown quantity at this point
Quote:
Originally Posted by Tolnaftate2004
float(string) will make it a number.
I don't know about GScript but isn't float for decimals?
__________________
-Mher Avetian
Reply With Quote
  #7  
Old 05-31-2006, 02:51 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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)

Quote:
Originally Posted by xXziroXx
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.

PHP Code:
temp.kewlstring "Wee";
temp.varname "temp.kewlstring";
echo(
makevar(temp.varname)); 
Would output: Wee
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")

Last edited by Skyld; 05-31-2006 at 01:02 PM..
Reply With Quote
  #8  
Old 05-31-2006, 05:09 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
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
Reply With Quote
  #9  
Old 05-31-2006, 05:47 AM
Omini Omini is offline
Millenium Owner
Join Date: Feb 2006
Location: N.Ireland
Posts: 293
Omini is on a distinguished road
Send a message via AIM to Omini Send a message via MSN to Omini Send a message via Yahoo to Omini
Alright, thanks for your help.
__________________




Last edited by Skyld; 05-31-2006 at 01:01 PM..
Reply With Quote
  #10  
Old 05-31-2006, 06:08 AM
Omini Omini is offline
Millenium Owner
Join Date: Feb 2006
Location: N.Ireland
Posts: 293
Omini is on a distinguished road
Send a message via AIM to Omini Send a message via MSN to Omini Send a message via Yahoo to Omini
Quote:
Originally Posted by Yen
Are you sure your server's GS2 enabled?
Yes, I am 100% positive. I tested with this -

NPC Code:
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

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



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

Quote:
Originally Posted by jake13jake
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).
__________________



Reply With Quote
  #11  
Old 05-31-2006, 07:10 AM
Omini Omini is offline
Millenium Owner
Join Date: Feb 2006
Location: N.Ireland
Posts: 293
Omini is on a distinguished road
Send a message via AIM to Omini Send a message via MSN to Omini Send a message via Yahoo to Omini
Uh ok it works now, heh heh. I found the problem. There was an error in the script before hand where it had

NPC Code:
if (client.cxclip == "on") { }



instead of

NPC Code:
if (client.cx == "on") { }



Heh.
__________________



Reply With Quote
  #12  
Old 05-31-2006, 02:10 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #13  
Old 05-31-2006, 03:35 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by Omini
NPC Code:
function onKeypressed(character)
{
if (character == "s") {
if (client.cx == "on") {
putaway();
}
}
}

NPC Code:
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.
Reply With Quote
  #14  
Old 05-31-2006, 05:58 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
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.
Reply With Quote
  #15  
Old 06-01-2006, 01:37 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by xAndrewx
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.


Quote:
Originally Posted by jake13jake
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.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #16  
Old 06-01-2006, 05:17 AM
Omini Omini is offline
Millenium Owner
Join Date: Feb 2006
Location: N.Ireland
Posts: 293
Omini is on a distinguished road
Send a message via AIM to Omini Send a message via MSN to Omini Send a message via Yahoo to Omini
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
__________________



Reply With Quote
  #17  
Old 06-01-2006, 11:14 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Omini
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:42 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.