Can't create 2D array variable in enumerator? -
unSatisfied - 08.07.2015
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?
Re: Can't create 2D array variable in enumerator? -
unSatisfied - 08.07.2015
Bump, I would really appreciate an answer!!
Re: Can't create 2D array variable in enumerator? -
dusk - 08.07.2015
No, you can not. But there is a
workaround.
Re: Can't create 2D array variable in enumerator? -
unSatisfied - 08.07.2015
Quote:
Originally Posted by dusk
|
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!!
Re: Can't create 2D array variable in enumerator? -
unSatisfied - 08.07.2015
Quote:
Originally Posted by dusk
|
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 = 0; factionRank < MAX_FACTION_RANKS; factionRank++)
{
format(variableName, sizeof(variableName), "RankName%d", (factionRank++));
cache_get_field_content(i, variableName, EditFaction[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];
Re: Can't create 2D array variable in enumerator? -
liquor - 08.07.2015
sizeof doesn't work on 2D arrays, specify a size instead.
Re: Can't create 2D array variable in enumerator? -
unSatisfied - 08.07.2015
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];
Re: Can't create 2D array variable in enumerator? -
liquor - 08.07.2015
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.
Re: Can't create 2D array variable in enumerator? -
unSatisfied - 08.07.2015
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.
Re: Can't create 2D array variable in enumerator? -
Pottus - 08.07.2015
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.