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

Compiler throwing back warnings (enums + Cell Array)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lord_Destros
Veteran Member
Join Date: Jul 2004
Location: With stupid.
Old 12-19-2009 , 05:56   Compiler throwing back warnings (enums + Cell Array)
Reply With Quote #1

Heh, it's been a while since I've been here .

Can anyone explain why a code piece such as the following would cause the compiler to throw a tag mismatch error? For whatever reason, I keep receiving such warnings when using an enum to define a cell location in an array pointing to a Cell Array.

Code:
#include <amxmodx> #include <cellarray> enum MOTD_FIELDS {     NAME = 0,     COMMAND,     PATH,     PAGES     //CATEGORY } new Array:messageProperties[MOTD_FIELDS] public cmdSay(id,mode,args[]) {     new comparedString[MAX_STRING_LENGTH], cellArraySize = ArraySize(messageProperties[NAME])     replace_all(args,strlen(args)," ","")     for (new ctr = 0; ctr < cellArraySize; ctr++)     {         ArrayGetString(messageProperties[COMMAND],ctr,comparedString,MAX_STRING_LENGTH-1)         if(equali(args,comparedString))         {             menu_cancel(id)             preparePageSelectionMenu(id, ctr)             return PLUGIN_HANDLED         }     }     return PLUGIN_CONTINUE }

The lines containing ArraySize and ArrayGetString functions throw warnings. However, doing something such as the following within a function works and compiles without warning/error.

Code:
    messageProperties[NAME] = ArrayCreate(MAX_STRING_LENGTH, 1)     messageProperties[COMMAND] = ArrayCreate(MAX_STRING_LENGTH, 1)     messageProperties[PATH] = ArrayCreate(MAX_STRING_LENGTH, 1)     messageProperties[PAGES] = ArrayCreate(1, 1)

Am I not understanding how enums work, does Cell Array merely not like enums, or does the compiler simply hate me.
__________________
Quote:
Originally Posted by Twilight Suzuka
Don't worry m'lord. The turtles day will come.

Last edited by Lord_Destros; 12-19-2009 at 06:06.
Lord_Destros is offline
Send a message via AIM to Lord_Destros
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 12-19-2009 , 06:02   Re: Compiler throwing back warnings (enums + Cell Array)
Reply With Quote #2

enum _:MOTD_FIELDS
__________________
xPaw is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-19-2009 , 06:51   Re: Compiler throwing back warnings (enums + Cell Array)
Reply With Quote #3

No..

@Lord_Destros: If you use an enum as structure, the proper way is :

Code:
#include <amxmodx> enum MOTD_FIELDS {     Array:Name,     Array:Command,     Array:Path,     Array:Pages }; new Array:messageProperties[ MOTD_FIELDS ]; public cmdSay( id, mode, args[] ) {     new comparedString[ MAX_STRING_LENGTH ];     new cellArraySize = ArraySize( messageProperties[ Name ] );     replace_all( args, strlen( args ), " ", "" );     for ( new ctr = 0; ctr < cellArraySize; ctr++ )     {         ArrayGetString( messageProperties[ Command ], ctr, comparedString, MAX_STRING_LENGTH - 1 );                 if ( equali( args, comparedString ) )         {             menu_cancel( id );             preparePageSelectionMenu( id, ctr );             return PLUGIN_HANDLED;         }     }         return PLUGIN_CONTINUE }

Code:
messageProperties[ Name ] = ArrayCreate( MAX_STRING_LENGTH, 1 ) messageProperties[ Command ] = ArrayCreate( MAX_STRING_LENGTH, 1 ) messageProperties[ Path ] = ArrayCreate( MAX_STRING_LENGTH, 1 ) messageProperties[ Pages ] = ArrayCreate( 1, 1 )

By the way, you should use trie to avoid to loop/get string/compare.
__________________
Arkshine is offline
Lord_Destros
Veteran Member
Join Date: Jul 2004
Location: With stupid.
Old 12-19-2009 , 21:27   Re: Compiler throwing back warnings (enums + Cell Array)
Reply With Quote #4

@xPaw: I already tried that but it didn't work.

@Arkshine: I tried setting Array tags within the enum but unfortunately all of the tag mismatch warnings remain.

Also, I'm not sure I see if use of trie would help as, based on my current storage method, I require the location at which the Command string exists within the cellarray (which links it to the respective Name/Path values).
__________________
Quote:
Originally Posted by Twilight Suzuka
Don't worry m'lord. The turtles day will come.

Last edited by Lord_Destros; 12-19-2009 at 21:29.
Lord_Destros is offline
Send a message via AIM to Lord_Destros
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-20-2009 , 07:07   Re: Compiler throwing back warnings (enums + Cell Array)
Reply With Quote #5

I've tested myself before posting, try again.
__________________
Arkshine is offline
Lord_Destros
Veteran Member
Join Date: Jul 2004
Location: With stupid.
Old 12-20-2009 , 19:19   Re: Compiler throwing back warnings (enums + Cell Array)
Reply With Quote #6

Quote:
Originally Posted by Arkshine View Post
I've tested myself before posting, try again.
Thanks. I forgot to remove the "_:" tag which prevented your suggestion from taking effect. Everything compiles fine now .
__________________
Quote:
Originally Posted by Twilight Suzuka
Don't worry m'lord. The turtles day will come.
Lord_Destros is offline
Send a message via AIM to Lord_Destros
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-20-2009 , 19:31   Re: Compiler throwing back warnings (enums + Cell Array)
Reply With Quote #7

You should cast only when you have no choice to do it like when a param of native/forward header doesn't have a tag and you would need to remove it.

You can read an interesting discussion here : http://forums.alliedmods.net/showthread.php?t=109853
__________________

Last edited by Arkshine; 12-20-2009 at 19:37.
Arkshine 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 06:13.


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