int ?

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

int ?

Post by ViPER »

if(int(getcvar "this") != 1) or if(int(getcvar "that") != "1")

or

if(int(getcvar this1) != "1") or if(int(getcvar this1) != 1)

or same with if(getcvar this1 != "1")

what do the quotes do/mean and how should they be used?
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Quotes mean that this is a value of type string. The getcvar command always returns a string. I always convert integer cvars to integer variables:
local.intvar = int(getcvar("integercvar"))
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

When you use int you convert or read the cvar as a number so the quotes should not be used like rookie said , the same goes when you use float .
Image
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

ok, i get the int. but what is float? cus i get float error when im fooling with these quotes.
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

an integer is a whole number like 1 or 2 a float is decimal like 1.5 or 3.9 you may have seen it when creating random numbers as well

local.num = randomint(26) 0 to 25

local.num = randomfloat(26) 0 to 25.9999 ? not sure now many decimal places it uses may only be 2 or could be 10 I don't know

The point is don't use quotes with numbers as was said if you don't use int(getvar whatever) then you will get a string you can use quotes in that case

if( (getcvar whatever) == "1") // ok

if ( int( getcvar whatever) == "1") // wrong

if ( int( getcvar whatever) == 1) //ok
Image
Post Reply