AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Float variable/Cvar (https://forums.alliedmods.net/showthread.php?t=84804)

Mlk27 02-01-2009 04:07

Float variable/Cvar
 
i have a confusion with this type of var/cvar

1. if we create a pcvar float eg

Code:

new Float:g_Health
g_health = register_cvar("amx_health", "20")

Code:

new g_Health2
g_health2 = register_cvar("amx_health2", "20.0")

what's the default value in g_Health and g_Health2 ?


2. which of these is correct to store health value in float?

new Float:g_clienthealth = float(get_user_health(id)); or

new Float:g_clienthealth = get_user_health(id); or

new g_clienthealth = float(get_user_health(id))


3. are all values returned from pev, in float? eg pev_health.

Arkshine 02-01-2009 04:35

Re: Float variable/Cvar
 
1. The output of register_cvar() is a pointer. Nothing to do with float. Pointer must be used with get_pcvar_[num|float|string]. [ Edit: It doesn't matter if you write 20 or 20.0, depending if you want an int or float, use get_pcvar_num or get_pcvar_float.

2. The output of get_user_health is an integer number. If you specify the Float: tag ; you have to convert it in float. Only your first example is right. Though using float here is pointless.

3. Float are passed by reference in pev. Depending the pev it can be a float, integer or vector. pev_health is a float ( it means you have to write a float value like 80.0 if you use set_pev ) but you can retrieve its value as int. Basically, if the field of pev is a float you must write a float number to set a value, but you can retrieve the value either as integer either as float. ( If you have for example : pev_fuser1 contening 52.26, pev ( id, pev_fuser1 ) will return 52 and pev ( id, pev_fuser1, MyVar ), MyVar will return 52.26.

Edit : xPaw, you're totaly wrong..


All times are GMT -4. The time now is 01:40.

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