Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-24-2006, 03:28 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
detect number

Well, I've been searching and stuff, I only found the answer to check if the number contains decimals, well I want to check if the float/string is a number, not a string or anything, anyone have an example or can tell me how to detect if a string/variable is a number?
__________________
Reply With Quote
  #2  
Old 12-24-2006, 08:47 PM
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
Quote:
Originally Posted by Chompy View Post
Well, I've been searching and stuff, I only found the answer to check if the number contains decimals, well I want to check if the float/string is a number, not a string or anything, anyone have an example or can tell me how to detect if a string/variable is a number?
PHP Code:
if (float(var) == var) {
  
// we have a number.

__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #3  
Old 12-24-2006, 09:32 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Tolnaftate2004 View Post
PHP Code:
if (float(var) == var) {
  
// we have a number.

Didn't work :O

PHP Code:
function onCreated()
{
  var = 
"test";
  if (
float(var) == var)
    echo(var @ 
" is a number.");

test is a number
__________________
Reply With Quote
  #4  
Old 12-24-2006, 09:46 PM
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
That's really weird...

Anywho:
PHP Code:
if (float(var) != -|| var == "-1"
I guess when comparing a string to a floating point/integer, it's treated as -1... :/
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #5  
Old 12-24-2006, 09:58 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Tolnaftate2004 View Post
That's really weird...

Anywho:
PHP Code:
if (float(var) != -|| var == "-1"
I guess when comparing a string to a floating point/integer, it's treated as -1... :/
Works Thanks
__________________
Reply With Quote
  #6  
Old 12-25-2006, 08:51 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Why not just use type..
Quote:
Wiki:
You can check the current type with the type()-function - obj.type() returns 0,1,2,3 for numeric, string, object or array.
NPC Code:

function onCreated()
{
var = 333;
if (var.type() == 0)
echo(var @ " is a number. GG LOL");
}

__________________
Quote:
Reply With Quote
  #7  
Old 12-27-2006, 06:15 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by fowlplay4 View Post
Why not just use type..

NPC Code:

function onCreated()
{
var = 333;
if (var.type() == 0)
echo(var @ " is a number. GG LOL");
}

Hmm, didn't think of that :O Thanks
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 11:53 PM.


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