14.11.2014, 05:56
This is driving me crazy and I'm not sure what the cause of it is. Basically I have an enumerator for my player data:
This works fine, but due to the way I check some team related things, I need the player's team to default to value (let's say 1). I know I could do this in OnPlayerConnect with PlayerData[playerid][Team] = 1;, which I was doing but I would like to just initialize "Team" inside the enum. I did some searching and everywhere I can find info shows that the following should work:
But it doesn't. By adding the "= 1" I get CnC.pwn(79 -- 80) : error 008: must be a constant expression; assumed zero and I get CnC.pwn() : error 032: array index out of bounds (variable "PlayerData") for every line that references the enum.
I tried adding a comma and a semicolon after " = 1" and neither worked and then I tried moving "Team" elsewhere in the enum and noticed that as long as it's not the last thing in the enum, it works fine.
Moving it so it's not the last item and has a comma after works fine and all but I'd really like to know why this is because in the future I may have an enum that requires me to initialize each part and I can't initialize the last one except by doing it outside in another function.
https://sampforum.blast.hk/showthread.php?tid=318307
Is the thread that I looked at and it shows that it should work fine. Plus I read several pieces of documentation on PAWN, C++ and other languages with similar syntax and it seems that it should work.
Код:
enum pData { Username[NAME_LENGTH], Password[PASSWORD_LENGTH], Admin, Mute, Frozen, Jail, Cell, Wanted, Money, Score, LastIP[IP_LENGTH], LoginAttempts, LoggedIn, Team }; new PlayerData[MAX_PLAYERS][pData];
Код:
enum pData { Username[NAME_LENGTH], Password[PASSWORD_LENGTH], Admin, Mute, Frozen, Jail, Cell, Wanted, Money, Score, LastIP[IP_LENGTH], LoginAttempts, LoggedIn, Team = 1 }; new PlayerData[MAX_PLAYERS][pData];
I tried adding a comma and a semicolon after " = 1" and neither worked and then I tried moving "Team" elsewhere in the enum and noticed that as long as it's not the last thing in the enum, it works fine.
Код:
enum pData { Username[NAME_LENGTH], Password[PASSWORD_LENGTH], Admin, Mute, Frozen, Jail, Cell, Wanted, Money, Score, LastIP[IP_LENGTH], LoginAttempts, Team = 1, LoggedIn }; new PlayerData[MAX_PLAYERS][pData];
https://sampforum.blast.hk/showthread.php?tid=318307
Is the thread that I looked at and it shows that it should work fine. Plus I read several pieces of documentation on PAWN, C++ and other languages with similar syntax and it seems that it should work.