Initialize Enum Value
#1

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:
Код:
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];
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:
Код:
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];
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.

Код:
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];
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.
Reply
#2

EDIT:NVM
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
1) That tutorial says nothing of the sort. It mentions that syntax, then goes on to explain what it is used for (and if you still need clarification, that's what pawn-lang.pdf is for).

2) PAWN is not C++! Just because you can do something in an entirely different language that happens to look a little superficially similar, does NOT mean you can do it in PAWN. If you want to learn C++, that's fine; if you want to learn PAWN, that's fine; just don't assume that ANY knowledge translates!
Код:
enum
    e_PlayerInfo
{
    SCORE,
    MONEY = 9,
    KILLS = 5,
    DEATHS = 56
};

new pInfo[MAX_PLAYERS][e_PlayerInfo];

printf("%i | %i | %i | %i", pInfo[0][SCORE], pInfo[0][MONEY], pInfo[0][KILLS], pInfo[0][DEATHS]);
That is literally pulled from the thread and shows exactly what I want.

I didn't say PAWN was C++ or any other language. I couldn't find what I was looking for in pawn-lang.pdf (I'm sure it's in there somewhere but I couldn't find it). Also, from my experience with C++ and previous research, the syntax is extremely similar so I thought I would try it, and according to that thread it's identical (at least in the case of enumerators).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)