Enumerations
#1

I'm having trouble with enumerations, doing something wrong but have no idea what

This is what i'm trying to do

pawn Код:
enum connections_Data {
    cuniqueID,
    cname[126],
    cleader[126],
    cmaxranks,
    crankname[13][24],
    cbank
};
new connectionData[999][connections_Data];
pawn Код:
crankname[13][24],
I want that to be a string with 12 options

So for example i could do
pawn Код:
format(connectionData[crankname][1], 24, "example 1");
format(connectionData[crankname][2], 24, "example 2");
Reply
#2

Shouldn't it be:
Код:
connectionData[something][crankname][1]
instead of
Код:
crankname[1]
Reply
#3

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Shouldn't it be:
Код:
connectionData[something][crankname][1]
instead of
Код:
crankname[1]
I've been doing that, sorry, updated the original post.

I do that and get
Код:
C:\Users\Jack\Documents\SA-MP 0.3.7 R2\gamemodes\outback.pwn(670) : error 001: expected token: "}", but found "["
C:\Users\Jack\Documents\SA-MP 0.3.7 R2\gamemodes\outback.pwn(705) : error 017: undefined symbol "cbank"
Exact code im trying to do
pawn Код:
for(new i = 0; i < sizeof(connectionData[conID][cmaxranks]); i++)
                        {
                            format(str2, sizeof(str2), "%s\n%d %s", str2, i+!, connectionData[conID][crankname][i]);
                        }
but the errors within the enumeration
Reply
#4

I'm not exactly sure, but I think what's causing the problem is
Код:
sizeof(connectionData[conID][cmaxranks])
I don't think you can do that, I think you need to manually input the size.
Reply
#5

That's a 4D array which is not supported. The most common solution would be to use crankname out of the enumerator. Zeex's patch for the compiler supports 4D arrays but not sure if your case would work.
Reply
#6

Quote:
Originally Posted by Stinged
Посмотреть сообщение
I'm not exactly sure, but I think what's causing the problem is
Код:
sizeof(connectionData[conID][cmaxranks])
I don't think you can do that, I think you need to manually input the size.
The error wasn't on that line but i changed it to 13 instead, but still got the error

The error is within these lines
pawn Код:
enum connections_Data {
    cuniqueID,
    cname[126],
    cleader[126],
    cmaxranks,
    crankname[MAX_CON_RANKS][24], // 670
    cbank // this is used on line 705 and is undefined because of the error above
};
Код:
C:\Users\Jack\Documents\SA-MP 0.3.7 R2\gamemodes\outback.pwn(670) : error 001: expected token: "}", but found "["
C:\Users\Jack\Documents\SA-MP 0.3.7 R2\gamemodes\outback.pwn(705) : error 017: undefined symbol "cbank"
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
That's a 4D array which is not supported. The most common solution would be to use crankname out of the enumerator. Zeex's patch for the compiler supports 4D arrays but not sure if your case would work.
Ah ok, explains it all, thanks
Reply
#8

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
That's a 4D array which is not supported. The most common solution would be to use crankname out of the enumerator. Zeex's patch for the compiler supports 4D arrays but not sure if your case would work.
problem is here enum connections_Data {
...
crankname[13][24],
};
You can't have a 2D array in an enum afaik, thats your problem.

you need to move those into their own array.

Btw you could technically have a 4D array, with having an array inside enum that you use to declare a 3D array.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)