SA-MP Forums Archive
Question regarding enums - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Question regarding enums (/showthread.php?tid=274184)



Question regarding enums - Scarred - 04.08.2011

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! :(



Re: Question regarding enums - RyDeR` - 04.08.2011

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



Re: Question regarding enums - Scarred - 04.08.2011

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.


Re: Question regarding enums - sleepysnowflake - 04.08.2011

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

This should help just fine ^^

And yes you can do. There is also explained how.


Re: Question regarding enums - Scarred - 04.08.2011

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])


Re: Question regarding enums - RyDeR` - 04.08.2011

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).


Re: Question regarding enums - Scarred - 04.08.2011

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!


Re: Question regarding enums - sleepysnowflake - 04.08.2011

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


Re: Question regarding enums - Scarred - 04.08.2011

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.


Re: Question regarding enums - sleepysnowflake - 04.08.2011

Yeah no problem. Welcome dude!