AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect variable type (https://forums.alliedmods.net/showthread.php?t=75141)

hebusletroll 07-31-2008 05:51

Detect variable type
 
Hi friends,

Is there any way to detect a variable type like this :

new Float:myfloat,myinteger,mystring[]

switch(vartype(myfloat))
{
case 0: //integer
case 1: //float
case 2: //string
}

Arkshine 07-31-2008 11:06

Re: Detect variable type
 
The main problem how to pass a var into a function which can be a float, string or integer. I don't think it's possible.

Otherwise, to see if it's a string, see if the last case is null-terminated, for float, convert into string and see if you see '.', else it's an integer. :mrgreen:

Anyway, I'm interested why would you need something like that. Can you provide more informations ? Maybe there another way to do what you want at the end.

jim_yang 07-31-2008 23:16

Re: Detect variable type
 
If you want to get the type of a var, that make no sense.
since pawn only have one type called cell, block of memory
a tag decide which type a var is.
same bits with different tags have different value.

danielkza 08-01-2008 03:34

Re: Detect variable type
 
Not sure if this works,but i've seen it in Pawn docs:
Code:

public plugin_init()
{
    new Float:myvar
    if(tagof myvar == tagof Float)
        server_print("is float")
    else
        server_print("not float")
}


hebusletroll 08-01-2008 17:58

Re: Detect variable type
 
Hello all !

@Arkshine, it's more difficult : i dont want to test if the data contain a float value, but i want to test if target variable is a float or not, with this test, it's possible to make a str_to_num or str_to_float in destination variable.

Some function like format accept many various type of variable, i think it is also possible with Pawn code.

@danielkza

Ok i will test now ! Thanks !

EDIT : @danielkza : I LOVE YOU ! THAT EXCATLY WHAT I WANT !!!!! (But you can't make the test "tagof Float", it's not a problem).
Karma for you !


All times are GMT -4. The time now is 05:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.