AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Global Array + Enum Struct (https://forums.alliedmods.net/showthread.php?t=324628)

SawceGal 05-21-2020 16:42

Global Array + Enum Struct
 
I'm using this but I get "warning 213: tag mismatch".

PHP Code:

enum struct enumWeaponClass
{
    
char WEAPONCLASS[32];
    
int WEAPONLEVEL;
    
CSWeaponID WEAPONID;
}

enumWeaponClass gWeaponClass[][] = 
{
    {
"M4A1 Anti Zombie"4CSWeapon_M4A1}



Fyren 05-21-2020 19:00

Re: Global Array + Enum Struct
 
The short answer is if you want a 1D array of enumWeaponClasses, then you declared your variable with too many dimensions.

The longer answer is fixing it still won't work on 1.10 due to a bug. It will work in spcomp in SM builds since mid-December. You also likely didn't provide all the output, since compiling what you gave above with the latest 1.10 and 1.11 produce an error in addition to warnings, or tell us which compiler version you're using.

SawceGal 05-21-2020 21:37

Re: Global Array + Enum Struct
 
I'm using 1.10, I can upgrade to 1.11 if the bug is fixed.

It won't compile "cannot call methods on an array", but also gives a tag mismatch warning.

This is an example of what I'm trying to do:

PHP Code:

#include <sourcemod>
#include <cstrike>

enum struct enumWeaponClass 

    
char WEAPONCLASS[32]; 
    
int WEAPONLEVEL
    
CSWeaponID WEAPONID


enumWeaponClass gWeaponClass[][] =  

    {
"M4A1 Anti Zombie"4CSWeapon_M4A1},
    {
"Scar"8CSWeapon_SCAR20
}

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_playerclass"ConCmdWeaponClass);
}

public 
Action ConCmdWeaponClass(int clientint args)
{
    for(
int isizeof(gWeaponClass); i++)
        
PrintToChat(client"Class: %s."gWeaponClass[i].WEAPONCLASS);


What would be the best way to achieve that while keeping the code simple to read and easy to modify?

Fyren 05-22-2020 13:22

Re: Global Array + Enum Struct
 
Quote:

It won't compile "cannot call methods on an array", but also gives a tag mismatch warning.
gWeaponClass[][] should be gWeaponClass[] if you want it to be a 1D array of your struct. Your most recent sample compiles with no warnings or errors with that change on 1.11.

The warnings and errors are both different ways of the compiler telling you that, since it can't know whether you really meant 1D or 2D.


All times are GMT -4. The time now is 22:07.

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