Looping through an enum -
zsoolt997 - 15.01.2018
Good evening!
I have a faction system in which I can set different names to different ranks.
When I rename a rank, I do this:
Код:
for(new i = 1; i <= MAX_FACTION_RANK; i++)
{
if(i == rank)
{
format(factionRank[cInfo[playerid][char_faction]][_e_faction_rank:i], MAX_FACTION_RANK_NAME, new_rankname);
mysql_tquery_format(zeus, "UPDATE faction_rank SET faction_rank_%d = '%s' WHERE faction_id = '%d'", i, factionRank[cInfo[playerid][char_faction]][_e_faction_rank:i], cInfo[playerid][char_faction]);
break;
}
}
But when I want to show all of the rank names, it shows very strange names:
Код:
[19:51:46] testrank
[19:51:46] estrank
[19:51:46] strank
[19:51:46] trank
[19:51:46] rank
[19:51:46] ank
[19:51:46] nk
[19:51:46] k
[19:51:46]
[19:51:46]
The code what I am using:
Код:
for(new i = 1; i <= MAX_FACTION_RANK; i++)
SendClientMessageEx(playerid, -1, "%s", factionRank[1][_e_faction_rank:i]);
So, my question is: what am I doing wrong?
Thanks in advance.
Re: Looping through an enum -
chneubeul - 15.01.2018
Hello, you don't have to use the label of the enum but, the variable with the enum declared in. exemple :
enum rank
{
POLICE,
GANG
}
new faction[rank];
see you
Re: Looping through an enum -
Misiur - 15.01.2018
Well, enums are tricky bests. Read up
https://sampforum.blast.hk/showthread.php?tid=318307
If you have
pawn Код:
enum _e_faction_rank {
a[32],
b[32]
}
Then _:a == 0 and _:b == 32
As for particular reason for what you see: string is just an array ended with NUL/0/'\0'/EOS (all the same value of 0), and all string functions know when string ends when they see it. See
pawn Код:
new boop[] = "Hello world";
print(boop); //Hello world
print(boop[3]); //lo world
Re: Looping through an enum -
zsoolt997 - 16.01.2018
OK, so basically I am doing this in a more complex way:
Код:
new string[20] = "some string";
for(new i; i < sizeof string; i++)
printf("%s", string[i]);
That's clear. My question is: how can I reach the data which is contained in the enum? With this kinda method.
Thanks in advance.
Re: Looping through an enum -
MP2 - 17.01.2018
Please show how your enum is declared.