Raised This Month: $32 Target: $400
 8% 

error 117: enum structs cannot be indexed as arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
enderandrew
Senior Member
Join Date: Jun 2020
Old 07-10-2020 , 22:09   error 117: enum structs cannot be indexed as arrays
Reply With Quote #1

So I'm not really a developer by trade. I took a few programming courses 25 years ago and haven't really done any serious coding since then.

I'm not sure which language Sourcepawn is closest to, but I'm tempted to pick up a decent beginner programming book and learning it properly. For the moment I'm dipping my toes in the water and trying to learn basics by updating many of the plugins I'm currently testing to new syntax. I've updated dozens with no issues. Then I tried to tackle STAMM, which is 45 plugins plus various includes. And of that project, I can get 44 out of 45 to compile just with #pragma newdecls required.

But I'm struggling to update cstrike_weapons.inc for some reason.

Here is that include file as I've attempted to update it:

https://pastebin.com/rrfnhPsY

Code:
SourcePawn Compiler 1.10.0.6490
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC

C:\tf2_server\tf\addons\sourcemod\scripting\include\cstrike_weapons.inc(231) : error 117: enum structs cannot be indexed as arrays
C:\tf2_server\tf\addons\sourcemod\scripting\include\cstrike_weapons.inc(309) : error 117: enum structs cannot be indexed as arrays
C:\tf2_server\tf\addons\sourcemod\scripting\include\cstrike_weapons.inc(314) : error 117: enum structs cannot be indexed as arrays
stamm_no_restrict.sp(37) : warning 241: Array-based enum structs will be removed in 1.11. See https://wiki.alliedmods.net/SourcePawn_Transitional_Syntax#Enum_Structs

3 Errors.
Three three errors are similiar lines:

SetTrieArray(hWeaponInfoTrie, weaponNames[WeaponID:i] , info[0], _:WeaponInfo);

As for that warning, I've converted other enums to enum structs, but stamm_no_restrict.sp(37) is referencing enum WeaponID which looks to have fixed values and shouldn't need to be a struct as far as I can tell, and I attempt to change it to an enum struct then a lot more breaks.
enderandrew is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 07-11-2020 , 09:50   Re: error 117: enum structs cannot be indexed as arrays
Reply With Quote #2

The issue is actually with info[0], which is a WeaponInfo struct -- it sounds like you want to access one of the fields e.g. info.InfoID.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 07-11-2020 , 10:51   Re: error 117: enum structs cannot be indexed as arrays
Reply With Quote #3

First of all, SourcePawn is closer to Pawn language, syntax (at least new 1.7 syntax) is closer to C/C++ but without actual OOP.
And as nosoop said, you shouldn't try to access enum struct fields by index (like with any array), use field name.
Like:

Code:
enum struct Player { // enum struct named "Player"
   bool Alive;
   int Health;
   int Kills;
   int Deaths;
   // etc
}

Player g_Player[MAXPLAYERS + 1];
public void OnPluginStart() {
   HookEvent( "player_spawn", OnPlayerSpawn );
}

public void OnPlayerSpawn(Event event, const char[] name, bool dontBroadcast) {
   int iClient = GetClientOfUserId( event.GetInt( "userid" ) );
   if ( iClient != 0 ) {
      g_Player[iClient].Health = GetClientHealth( iClient );
      g_Player[iClient].Alive = true;
   }
}
__________________

Last edited by MAGNAT2645; 07-11-2020 at 10:59.
MAGNAT2645 is offline
enderandrew
Senior Member
Join Date: Jun 2020
Old 07-11-2020 , 16:18   Re: error 117: enum structs cannot be indexed as arrays
Reply With Quote #4

Thanks!
enderandrew 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 21:09.


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