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

Global Array + Enum Struct


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SawceGal
Junior Member
Join Date: May 2020
Old 05-21-2020 , 16:42   Global Array + Enum Struct
Reply With Quote #1

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}

SawceGal is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-21-2020 , 19:00   Re: Global Array + Enum Struct
Reply With Quote #2

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.
Fyren is offline
SawceGal
Junior Member
Join Date: May 2020
Old 05-21-2020 , 21:37   Re: Global Array + Enum Struct
Reply With Quote #3

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?
SawceGal is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-22-2020 , 13:22   Re: Global Array + Enum Struct
Reply With Quote #4

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.

Last edited by Fyren; 05-22-2020 at 13:25. Reason: rephrase entire post
Fyren is offline
Reply


Thread Tools
Display Modes

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 10:44.


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