AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   float mismatch, wut (https://forums.alliedmods.net/showthread.php?t=196758)

Backstabnoob 09-25-2012 09:56

float mismatch, wut
 
PHP Code:

/* not important, just so you see how the enum is created */
enum Weapons
{
    
WEAPON_NONE 0,
    
WEAPON_OPENER,
    
WEAPON_AXE,
    
WEAPON_BOWIEKNIFE,
    
WEAPON_SAW
}

new const 
FloatcstDamageMultiplierWeapons ] =
{
    
1.0,
    
1.5,
    
2.0,
    
1.7,
    
2.5
}

/* not important, just so you see how the variable is initialized */
new Weaponsg_WeaponMAX_PLAYERS ] = WEAPON_NONE

/* in Ham_TakeDamage */
SetHamParamFloat4cstDamageMultiplierg_WeaponiAttacker ] ] ) 

Throws 5 tag mismatches, each one coming from the constant. What's wrong?

Arkshine 09-25-2012 10:47

Re: float mismatch, wut
 
If you use a tagged enum in an array, it will be considered as a data structure.

SetHamParamFloat() expects a Float.

It means, if you do that : cstDamageMultiplier[ g_Weapon[ iAttacker ] ] ; the output tag won't be from cstDamageMultiplier but from the member of the "structure" g_Weapon[ iAttacker ]. And WEAPON_* has no tag. That's why the compiler is crying.

You can solve by avoiding the use of tagged enum with an array :

Code:
enum {     WEAPON_NONE = 0,     WEAPON_OPENER,     WEAPON_AXE,     WEAPON_BOWIEKNIFE,     WEAPON_SAW,         WEAPON_COUNT }; new const Float:cstDamageMultiplier[ WEAPON_COUNT ] = {     1.0,     1.5,     2.0,     1.7,     2.5 } new  g_Weapon[ MAX_PLAYERS + 1 ] = WEAPON_NONE;

Backstabnoob 09-25-2012 11:27

Re: float mismatch, wut
 
Thanks for the explanation, it works well.


All times are GMT -4. The time now is 08:18.

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