AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Compiler throwing back warnings (enums + Cell Array) (https://forums.alliedmods.net/showthread.php?t=112366)

Lord_Destros 12-19-2009 05:56

Compiler throwing back warnings (enums + Cell Array)
 
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.

xPaw 12-19-2009 06:02

Re: Compiler throwing back warnings (enums + Cell Array)
 
enum _:MOTD_FIELDS

Arkshine 12-19-2009 06:51

Re: Compiler throwing back warnings (enums + Cell Array)
 
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.

Lord_Destros 12-19-2009 21:27

Re: Compiler throwing back warnings (enums + Cell Array)
 
@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).

Arkshine 12-20-2009 07:07

Re: Compiler throwing back warnings (enums + Cell Array)
 
I've tested myself before posting, try again.

Lord_Destros 12-20-2009 19:19

Re: Compiler throwing back warnings (enums + Cell Array)
 
Quote:

Originally Posted by Arkshine (Post 1023681)
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 :).

Arkshine 12-20-2009 19:31

Re: Compiler throwing back warnings (enums + Cell Array)
 
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


All times are GMT -4. The time now is 20:56.

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