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

Enum inside an enum - array too many subscripts


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-05-2014 , 07:41   Enum inside an enum - array too many subscripts
Reply With Quote #1

Hey, guys! I'm actually trying to make an upgrade menu where you have few sub-menues:
1. Grenades
2. HP
3. Armor
4. Critical damage
5. Speed
Well, all of them can be upgraded one time, except for the grenades. When you choose them, an sub-menu appears with all kinds of grandes. So I'm actually trying to put all the upgraded values in one variable and made it like with enum:
PHP Code:
enum _:eGrenades
{
    
HE,
    
Flash1,
    
Flash2,
    
Frost
}

enum _:eUpgrades
{
    
Grenades[eGrenades], //This is the critical line, no error here, but will thi work properly?
    
Health,
    
Armor,
    
CritDmg,
    
Speed
}

new 
player_upgrade[eUpgrades][33
The problem is that I've tried to put new character in the enum, which is already enum-tagged. No errors in the enums, but when I try to use player_upgrade like:
PHP Code:
player_upgrade[Grenades[HE]][id
it gives me an error:
Code:
Error: Invalid subscript (not an array or too many subscripts): "Grenades"
So, I'm asking why is this causinh, since the "Grenades" is tagged with those from the other enum. And is there a better way to make it?
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-05-2014 , 07:43   Re: Enum inside an enum - array too many subscripts
Reply With Quote #2

Try
PHP Code:
player_upgrade[Grenades][HE][id
klippy is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-05-2014 , 07:45   Re: Enum inside an enum - array too many subscripts
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
Try
PHP Code:
player_upgrade[Grenades][HE][id
The same. It actually doesn't make sense, I think, when the variable is created with two subscripts. The strange is why the error is appearing...
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-05-2014 , 07:52   Re: Enum inside an enum - array too many subscripts
Reply With Quote #4

Then
PHP Code:
player_upgrade[Grenades HE][id
should work I guess. Can't think of a correct way(if there is any) to access that "deep".

EDIT:
Actually, you should have created a variable like so
PHP Code:
new player_upgrade[33][eUpgrades]; 
and you will be able to access it as
PHP Code:
player_upgrade[id][Grenades][HE

Last edited by klippy; 08-05-2014 at 07:54.
klippy is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-05-2014 , 07:58   Re: Enum inside an enum - array too many subscripts
Reply With Quote #5

That actually worked pretty neat
Thanks, man, I would never guess that the possition of the subscripts matters
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-05-2014 , 08:06   Re: Enum inside an enum - array too many subscripts
Reply With Quote #6

You may want to leave a tag on these 2 enums (create them without _: before the name), so when indexing them you will most probably know if something went wrong because of tag mismatch. That way, you will be able to index the player_upgrade array with only these enum elements, making it more error-proof.
klippy is offline
Old 08-06-2014, 08:34
hleV
This message has been deleted by hleV.
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 16:02.


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