Can't create 2D array variable in enumerator?
#1

I have the following enumerator, and It will not let me create a 2D array variable:

// ----- [ FACTION VARIABLES ] -----
#define MAX_FACTION_RANKS 7
enum iFaction
{
ID,
Taken,
Type,
Name[128],
/*RankName1[50],
RankName2[50],
RankName3[50],
RankName4[50],
RankName5[50],
RankName6[50],
RankName7[50],*/
RankNames[MAX_FACTION_RANKS][50]
};

Any ideas why it won't let me create the RankNames variable? I'm a C# programmer and recently got into SAMP, and I'm currently making my own custom gamemode that is fully dynamic (using MySQL).

Errors:
error 001: expected token: "}", but found "["
error 010: invalid function or declaration

I assume the first error is created because the compiler is expecting me to identify the values in {}, however shouldn't it let me create 2D, 3D, etc arrays?
Reply
#2

Bump, I would really appreciate an answer!!
Reply
#3

No, you can not. But there is a workaround.
Reply
#4

Quote:
Originally Posted by dusk
Посмотреть сообщение
No, you can not. But there is a workaround.
Thanks, mind explaining the following line to me?

#define hStorage][%1][%2] hStorage][((%1)*hStorage_size2)+(%2)]

Such a big inconvenience for such a simple feature... -.- Thank you though!!
Reply
#5

Quote:
Originally Posted by dusk
Посмотреть сообщение
No, you can not. But there is a workaround.
I just tried the solution and it does not work unfortunately (I think it's because I'm using the variable for a string, rather than an int). My variable is RankNames[MAX_FACTION_RANKS][50] (50 being how long the string should be). I'm trying to set the value by doing the following, however it isn't working (using MySQL):

PHP код:
for(new factionRank 0factionRank MAX_FACTION_RANKSfactionRank++)
{
    
format(variableNamesizeof(variableName), "RankName%d", (factionRank++));
    
cache_get_field_content(ivariableNameEditFaction[i][RankNames][factionRank]);

EDIT: I guess I'll just have to declare a variable outside of the enumerator =/:
new EditFaction_RankNames[MAX_FACTIONS][MAX_FACTION_RANKS][50];
Reply
#6

sizeof doesn't work on 2D arrays, specify a size instead.
Reply
#7

Quote:
Originally Posted by liquor
Посмотреть сообщение
sizeof doesn't work on 2D arrays, specify a size instead.
It does.. and I still get an error with a static size. I just created the following variable and it works now (It's just not in the enumerator which kinda bothers me):

new EditFaction_RankNames[MAX_FACTIONS][MAX_FACTION_RANKS][50];
Reply
#8

I'm using 2D arrays in my script, and as long as i specify size instead of using sizeof, it works fine.
You'll also need to specify size instead of using sizeof when you retreive data from anywhere and store it.
Reply
#9

Quote:
Originally Posted by liquor
Посмотреть сообщение
I'm using 2D arrays in my script, and as long as i specify size instead of using sizeof, it works fine.
You'll also need to specify size instead of using sizeof when you retreive data from anywhere and store it.
You're using 2D arrays in an enumerator? By the way, I'm not using sizeof.. I'm using a predefined value. I feel like you didn't even read my OP.
Reply
#10

Yeah this is a pretty lousy solution I think here is what I would do.
Drop the this out of your enum and declare as a static.

Код:
static RankNames[MAX_FACTIONS][MAX_FACTION_RANKS][50] = { }
Best way to do this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)