Clearing out an enum?
#1

is there an easy way to erase everything in an enum without doing
pawn Код:
enum[VALUE1] = 0;
enum[VALUE2] = 0;
for the whole thing?
Reply
#2

pawn Код:
for(new i = 0; i < sizeof(enum); i++)
    enum[enumname:i] = 0;
}
Should do it, but it might not clear arrays properly when you got one in the enum.
Reply
#3

I think there is

pawn Код:
enum eEnum
{
    eVar1,
    eVar2,
    eVar3
}

new MyVar[eEnum];
pawn Код:
for(new i=0; i < sizeof(MyVar); i++)
{
    MyVar[eEnum:i] = 0;
}
Reply
#4

then how would i clear the array if it was setup like
pawn Код:
gPlayerInfo[playerid][PASSWORD]
where the PASSWORD is a 32 character array
Reply
#5

If you have this enum for example :


pawn Код:
enum Example
{
    xD,
    xO,
    xP,
};

new Var[Example];

You can't change the values of the symbols xD and xO inside the brackets, like:

pawn Код:
xD = 5;
xO = 4;
Because they are constant .


But if you want to do this without write one per one :

pawn Код:
new Var[xD] = 0;
new Var[xO] = 0;
new Var[xP] = 0;

Just use:

pawn Код:
for(new y = 0; y != sizeof(Var); y++)
{
    Var[Example:y] = 0;  //The tag "Example:" is derived from the enum "Example"
}



@EDIT

Quote:
Originally Posted by dowster
Посмотреть сообщение
then how would i clear the array if it was setup like
pawn Код:
gPlayerInfo[playerid][PASSWORD]
where the PASSWORD is a 32 character array
You can use:

pawn Код:
strmid(gPlayerInfo[playerid][PASSWORD],"",false,0,32);

To clean it .



I hope that i have helped .
Reply
#6

Quote:
Originally Posted by dowster
Посмотреть сообщение
then how would i clear the array if it was setup like
pawn Код:
gPlayerInfo[playerid][PASSWORD]
where the PASSWORD is a 32 character array
pawn Код:
for(new i=0; i < sizeof(gPlayerInfo[]); i++)
{
    gPlayerInfo[playerid][i] = 0;
}
Reply
#7

Hm, i got no idea if this will work, didnt test it, but maybe it works:

pawn Код:
new var[enum];

for (new i = 0; i < sizeof(var); i++)
{
    if (sizeof(var[enum:i]) > 1)
    {
        for (new j = 0; j < sizeof(var[enum:i]); j ++)
        {
            var[enum:i][j] = 0;
        } else {
            var[enum:i] = 0;
        }
    }
}
Reply
#8

Once again, the same basic code like in reply #3
pawn Код:
enum E_VAR {
    var1,
    var2[10],
    var3
}

new var[E_VAR];

for(new i; i < sizeof(var); i++) {
    var[E_VAR: i] = 0;
}
This is fully enough to clear all enum variables and arrays, due to the fact how enums work!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)