Raised This Month: $ Target: $400
 0% 

Detect variable type


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hebusletroll
Senior Member
Join Date: Apr 2006
Old 07-31-2008 , 05:51   Detect variable type
Reply With Quote #1

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
}
__________________
Boring about playing same weapons ? PowerWeapons is available !
PowerWeapon v1.0 released !
Play up to 70 new weapons and create your own weapons !
Tested on Windows Server 2003, 2008/R2, 2012 and Linux Ubuntu 10.x and CentOs 6.x
hebusletroll is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-31-2008 , 11:06   Re: Detect variable type
Reply With Quote #2

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.

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.
__________________
Arkshine is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 07-31-2008 , 23:16   Re: Detect variable type
Reply With Quote #3

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.
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-01-2008 , 03:34   Re: Detect variable type
Reply With Quote #4

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")
}
danielkza is offline
hebusletroll
Senior Member
Join Date: Apr 2006
Old 08-01-2008 , 17:58   Re: Detect variable type
Reply With Quote #5

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 !
__________________
Boring about playing same weapons ? PowerWeapons is available !
PowerWeapon v1.0 released !
Play up to 70 new weapons and create your own weapons !
Tested on Windows Server 2003, 2008/R2, 2012 and Linux Ubuntu 10.x and CentOs 6.x

Last edited by hebusletroll; 08-01-2008 at 18:08. Reason: Answer for Danielkza
hebusletroll is offline
Reply


Thread Tools
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 -4. The time now is 05:33.


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