Raised This Month: $ Target: $400
 0% 

float mismatch, wut


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 09-25-2012 , 09:56   float mismatch, wut
Reply With Quote #1

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?

Last edited by Backstabnoob; 09-25-2012 at 09:57.
Backstabnoob is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-25-2012 , 10:47   Re: float mismatch, wut
Reply With Quote #2

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;
__________________

Last edited by Arkshine; 09-25-2012 at 10:49.
Arkshine is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 09-25-2012 , 11:27   Re: float mismatch, wut
Reply With Quote #3

Thanks for the explanation, it works well.
Backstabnoob is offline
Reply



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 08:18.


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