Print enum variables.
#1

I have a pretty big enum and I want to print all it variables.

For example:

pawn Код:
enum
{
Kills,
Deaths,
Money,
PlayTime
}
I want a code that prints:
Kills
Deaths
Money
PlayTime



I know we can use enum loop to get the enum values, but I don't know how to do it to get the enum variables. Is it possible ?
Reply
#2

pawn Код:
//enum..
enum pInfo
{
    Kills,
    Deaths,
    Money,
    PlayTime
}
new PlayerInfo[MAX_PLAYERS][pInfo];

//Wherever..
new string[100];
format(string, sizeof(string), "Kills: %d, Deaths: %d, Money: %d, PlayTime: %d", PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], GetPlayerMoney(playerid), PlayerInfo[playerid][PlayTime]);
SendClientMessage(playerid, 0x0, string);

EDIT:

If you want it to print in logs do:

pawn Код:
//Wherever..
new string[100];
format(string, sizeof(string), "Kills: %d, Deaths: %d, Money: %d, PlayTime: %d", PlayerInfo[playerid][Kills], PlayerInfo[playerid][Deaths], GetPlayerMoney(playerid), PlayerInfo[playerid][PlayTime]);
printf(string);
Reply
#3

It's not that what I meant...

Whatever, I don't think its possible anyway.
Reply
#4

I know what you mean. You want to loop through an enum like it was an array. I need that too, I'm trying to make a function that saves all the enum data to a file (finally found use for tagof())

I think it's possible because sscanf somehow stores all the required info in the enum without actually passing it their names.
Quote:
Originally Posted by ******
pawn Код:
enum
    E_DATA
{
    E_DATE_C,
    Float:E_DATA_X,
    E_DATA_NAME[32],
    E_DATA_Z
}

main
{
    new
        var[E_DATA];
    sscanf("1 12.0 Bob c", "e<ifs[32]c>", var);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)