Raised This Month: $ Target: $400
 0% 

Iterating over enum structs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xerox8521
Senior Member
Join Date: Sep 2011
Old 07-03-2023 , 06:21   Iterating over enum structs
Reply With Quote #1

Hi,
I have this enum struct
PHP Code:
enum struct UpgradeInfo
{
    
bool bLoaded;
    
int iHealth;
    
int iDamage;
}

UpgradeInfo upgInfo[MAXPLAYERS+1]; 
and this char array:
PHP Code:
char szUpgradeNames[][] = 
{
    
"Health Upgrade",
    
"Damage Upgrade"
}; 
What I wanted to do is create menu entries like so:
PHP Code:
char szUpgradeInfo[32], szUpgradeNum[4];
for(
int i 0sizeof(szUpgradeNames); i++)
{
    
IntToString(iszUpgradeNumsizeof(szUpgradeNum));
    
Format(szUpgradeInfosizeof(szUpgradeInfo), "%s - %d"szUpgradeNames[i], upgInfo[client][i]);
    
menu.AddItem(szUpgradeNumszUpgradeInfo);

but this
PHP Code:
upgInfo[client][i// Wiki says: Note that even though enum structs are actually arrays, for the most part they cannot be used as arrays 
and
PHP Code:
upgInfo[client].
obviously do not work and I'm not sure how to solve this currently.
xerox8521 is offline
Kerouha
Member
Join Date: Jul 2015
Location: Russian Federation
Old 07-06-2023 , 07:49   Re: Iterating over enum structs
Reply With Quote #2

If my understanding is correct, one can not iterate over an enum struct.

Code:
upgInfo[client].bLoaded
upgInfo[client].iHealth
upgInfo[client].iDamage
This is how you're supposed to access your struct.
Kerouha 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 10:31.


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