Raised This Month: $51 Target: $400
 12% 

How is this a tag mismatch?


Post New Thread Reply   
 
Thread Tools Display Modes
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 07-16-2010 , 07:37   Re: How is this a tag mismatch?
Reply With Quote #11

Quote:
Originally Posted by Greyscale View Post
I can see how this is a tough problem to solve, though. Because sometimes I need to tag each enum member with a specific data type. The question is how can we tell the compiler what we want? The tag of the member or of the array.
I found the AMXx thread about this, look at this:

Quote:
Originally Posted by joaquimandrade View Post
I think it's interesting to understand the problem here.

And it is: when you are using a value defined as part of an enum to index an array, the compiler fails to detect the tag of the cells of the array.

Like:

PHP Code:
enum _:Coordinate
{
    
X,Y,Z
}

new 
Float:coordinates[Coordinate];

public 
plugin_init()
{
    new 
Float:value
    
    
// Tag mismatch
    
value coordinates[X]
    
    
// OK
    
value Float:coordinates[X]

    
// OK but is stupid
    
value coordinates[X]

Seta00 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 07-16-2010 , 07:38   Re: How is this a tag mismatch?
Reply With Quote #12

It is intentional that when using an enum value to index an array, the expression inherits the enum value's tag.
Fyren is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 07-16-2010 , 07:47   Re: How is this a tag mismatch?
Reply With Quote #13

Quote:
Originally Posted by Fyren View Post
It is intentional that when using an enum value to index an array, the expression inherits the enum value's tag.
Yeah, that's how the enum hack works...

@Greyscale
You'll have to tag every enumeration, like this:
Code:
enum SDKLibCalls {     #if defined PROJECT_GAME_CSS     Handle:SDKLibCall_TerminateRound,      /** Terminate the round with a given reason. */     Handle:SDKLibCall_CSWeaponDrop,        /** Force client to drop weapon. */     Handle:SDKLibCall_FlashlightIsOn,      /** Check is a client's flashlight is on. */     Handle:SDKLibCall_FlashlightTurnOn,    /** Turn a client's flashlight on. */     Handle:SDKLibCall_FlashlightTurnOff,   /** Turn a client's flashlight off. */     #endif }
Seta00 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 07-16-2010 , 07:56   Re: How is this a tag mismatch?
Reply With Quote #14

I'm just replying because you called it a "design flaw" when it is the intentional behavior.
Fyren is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 07-16-2010 , 08:09   Re: How is this a tag mismatch?
Reply With Quote #15

Quote:
Originally Posted by Fyren View Post
I'm just replying because you called it a "design flaw" when it is the intentional behavior.
It makes sense, else Pawn's "structure" would be impossible to make, but in cases like this, where the enum is used just to name integer indexes it's hard to see why it works that way.

By the way, an alternative solution would be removing the name of the enum, like this:
Code:
enum {     #if defined PROJECT_GAME_CSS     SDKLibCall_TerminateRound,      /** Terminate the round with a given reason. */     SDKLibCall_CSWeaponDrop,        /** Force client to drop weapon. */     SDKLibCall_FlashlightIsOn,      /** Check is a client's flashlight is on. */     SDKLibCall_FlashlightTurnOn,    /** Turn a client's flashlight on. */     SDKLibCall_FlashlightTurnOff,   /** Turn a client's flashlight off. */     #endif     SDKLibCalls }

Last edited by Seta00; 09-09-2010 at 17:05.
Seta00 is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 07-16-2010 , 14:26   Re: How is this a tag mismatch?
Reply With Quote #16

I use that enum for multiple arrays.

Code:
/**
 * The name of the sdkcall.  This is the name that should be used in the gamedata file.
 */
stock String:g_strSDKCallName[SDKLibCalls][] =
{
    "Placeholder"
    #if defined PROJECT_GAME_CSS
   ,"TerminateRound",
    "CSWeaponDrop",
    "FlashlightIsOn",
    "FlashlightTurnOn",
    "FlashlightTurnOff"
    #endif
};
Which works fine, without warnings, by the way.

I think the best solution is just to add whatever tag I need before the array name.

Code:
Handle:g_hSDKCalls[SDKCallLib_TerminateRound];
__________________
Greyscale is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 07-16-2010 , 15:14   Re: How is this a tag mismatch?
Reply With Quote #17

Quote:
Originally Posted by Greyscale View Post
I use that enum for multiple arrays.

Code:
/**
 * The name of the sdkcall.  This is the name that should be used in the gamedata file.
 */
stock String:g_strSDKCallName[SDKLibCalls][] =
{
    "Placeholder"
    #if defined PROJECT_GAME_CSS
   ,"TerminateRound",
    "CSWeaponDrop",
    "FlashlightIsOn",
    "FlashlightTurnOn",
    "FlashlightTurnOff"
    #endif
};
Which works fine, without warnings, by the way.
In this case, you're accessing the data on the second dimension, and there's only one type.

Quote:
I think the best solution is just to add whatever tag I need before the array name.

Code:
Handle:g_hSDKCalls[SDKCallLib_TerminateRound];
I'd remove the enum name, anyway it's your code, you decide what to do.
Seta00 is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 07-16-2010 , 15:42   Re: How is this a tag mismatch?
Reply With Quote #18

How am I going to index an array with an enum with no name?
__________________
Greyscale is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 07-16-2010 , 16:44   Re: How is this a tag mismatch?
Reply With Quote #19

PHP Code:
/**
 * List of available sdktools functions.
 */
enum
{
    
#if defined PROJECT_GAME_CSS
    
SDKLibCall_TerminateRound,      /** Terminate the round with a given reason. */
    
SDKLibCall_CSWeaponDrop,        /** Force client to drop weapon. */
    
SDKLibCall_FlashlightIsOn,      /** Check is a client's flashlight is on. */
    
SDKLibCall_FlashlightTurnOn,    /** Turn a client's flashlight on. */
    
SDKLibCall_FlashlightTurnOff,   /** Turn a client's flashlight off. */
    #endif
    
SDKLibCalls
}

/**
 * Handles to all the pre-defined sdkcalls.
 */
new Handle:g_hSDKCall[SDKLibCalls];

/**
 * Terminates the round. (CS:S)
 * 
 * @param delay     Time to wait before new round starts.
 * @param reason    Round end reason.  See enum RoundEndReasons.
 */
stock SDKToolsLib_TerminateRound(Float:delayRoundEndReasons:reason)
{
    
SDKCall(g_hSDKCall[SDKLibCall_TerminateRound], delay_:reason);
}

/**
 * Forces client to drop a weapon. (CS:S)
 * 
 * @param client    The client index.
 * @param weapon    The weapon entity index to force client to drop.
 */
stock SDKToolsLib_CSWeaponDrop(clientweapon)
{
    
SDKCall(g_hSDKCall[SDKLibCall_CSWeaponDrop], clientweapontruefalse);


Last edited by bl4nk; 07-17-2010 at 15:29. Reason: removed unintentional bbcode
Seta00 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 00:02.


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