Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   detect number (https://forums.graalonline.com/forums/showthread.php?t=70984)

Chompy 12-24-2006 03:28 PM

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?

Tolnaftate2004 12-24-2006 08:47 PM

Quote:

Originally Posted by Chompy (Post 1256840)
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.



Chompy 12-24-2006 09:32 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1256990)
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

Tolnaftate2004 12-24-2006 09:46 PM

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... :/

Chompy 12-24-2006 09:58 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1257014)
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 :D Thanks :)

fowlplay4 12-25-2006 08:51 PM

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");
}


Chompy 12-27-2006 06:15 PM

Quote:

Originally Posted by fowlplay4 (Post 1257340)
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 :)


All times are GMT +2. The time now is 08:15 AM.

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