Question regarding enums
#1

Instead of doing something like:

pawn Код:
enum player_Information {

        Achievement1
        Achievement2,
        Achievement3,
        ...
    }
Is it possible to do something like:

pawn Код:
enum player_Information {

        Achievements[4]
    }
So I could use them in the following syntax?

pawn Код:
if(cInfo[playerid][Achievements[0]] == 1) {
//You have achievement #1!
}
else return //You don't have achievement #1! :(
Reply
#2

Yes, but it should be like this:
pawn Код:
if(cInfo[playerid][Achievements][0] == 1)
Reply
#3

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Yes, but it should be like this:
pawn Код:
if(cInfo[playerid][Achievements][0] == 1)
So the example I used above would work? And yeah, lack of sleep, my bad.
Reply
#4

https://sampwiki.blast.hk/wiki/Keywords:Initialisers#enum

This should help just fine ^^

And yes you can do. There is also explained how.
Reply
#5

Well then, that's odd.. Never thought that would work.

Quick question though, how would I go about saving them using Y_INI? Because i'm assuming this wouldn't work:

pawn Код:
INI_WriteInt(playerFile, "Achievements", cInfo[playerid][Achievements]);
When there's 3 achievements (Achievements[4])
Reply
#6

You could do something like this:
pawn Код:
INI_WriteInt(playerFile, "Achievements_0", cInfo[playerid][Achievements][0]);
INI_WriteInt(playerFile, "Achievements_1", cInfo[playerid][Achievements][1]);
INI_WriteInt(playerFile, "Achievements_2", cInfo[playerid][Achievements][2]);
INI_WriteInt(playerFile, "Achievements_3", cInfo[playerid][Achievements][3]);
or write as a string and split them after read using sscanf (or something else your prefere).
Reply
#7

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
You could do something like this:
pawn Код:
INI_WriteInt(playerFile, "Achievements_0", cInfo[playerid][Achievements][0]);
INI_WriteInt(playerFile, "Achievements_1", cInfo[playerid][Achievements][1]);
INI_WriteInt(playerFile, "Achievements_2", cInfo[playerid][Achievements][2]);
INI_WriteInt(playerFile, "Achievements_3", cInfo[playerid][Achievements][3]);
or write as a string and split them after read using sscanf (or something else your prefere).
Right, thank you very much! Oh, and thanks to the other guy who replied with the enum wiki link -- that helps too!
Reply
#8

The way we thank thesse days is with reputation. That little black star icon under our avatars.
Reply
#9

Quote:
Originally Posted by Berlovan
Посмотреть сообщение
The way we thank thesse days is with reputation. That little black star icon under our avatars.
Right, new on these forums - My bad.
Reply
#10

Yeah no problem. Welcome dude!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)