[Solved] ResetPlayerInfo + Loop
#1

In the past I used to reset the player data by this way:
pawn Код:
ResetPlayerData(playerid)
{
  Var[playerid][ID] = 0;
  Var[playerid][Name] = EOS;
}
But it takes too long to add because there are a lot of cells for "Var". Then I thought, what if I use a loop? so I tried this:
pawn Код:
ResetPlayerData(playerid)
{
  for(new i = 0; i < MAX_P_VAR; i ++)
  {
    switch(i)
    {
      case 1..8: Var[playerid][i] = EOS; // this line error
      case 9, 15, 20: Var[playerid][i] = -1; // if I added this it would show another error
    }  
  }
}
But it returns an error.
Код:
mygm.pwn(168) : warning 213: tag mismatch
Is there a way to do what I want?
Reply
#2

Quote:
Originally Posted by SAWC™
pawn Код:
ResetPlayerData(playerid)
{
  for(new i = 0; i < MAX_P_VAR; i ++)
  {
    switch(i)
    {
      case: 1..8: Var[playerid][i] = EOS; // this line error
      case: 9, 15, 20: Var[playerid][i] = -1; // if I added this it would show another error
    }  
  }
}

case: 1..8: wrong
pawn Код:
case 1..8:
Reply
#3

Quote:
Originally Posted by Phento
Quote:
Originally Posted by SAWC™
pawn Код:
ResetPlayerData(playerid)
{
  for(new i = 0; i < MAX_P_VAR; i ++)
  {
    switch(i)
    {
      case: 1..8: Var[playerid][i] = EOS; // this line error
      case: 9, 15, 20: Var[playerid][i] = -1; // if I added this it would show another error
    }  
  }
}

case: 1..8: wrong
pawn Код:
case 1..8:
My bad, but that's not the error.
Reply
#4

Try;
pawn Код:
case 1..8: strcpy(Var[playerid][i], EOS);
strcpy if you don't have it (******);
pawn Код:
stock strcpy(dest[], src[])
{
    new i = 0;
    while ((dest[i] = src[i])) i++;
}
Reply
#5

It doesn't work, still returning the same error...

pawn Код:
enum pinfo{id, name, pass}
pawn Код:
new Var[MAX_PLAYERS][pinfo];
pawn Код:
ResetPlayerData(playerid)
{
  for(new i = 0; i < 3; i ++) // 0 == id, 1 == name, 2 == pass
  {
    switch(i)
    {
      case 0: Var[playerid][i] = -1;
      case 1, 2: Var[playerid][i] = EOS;
    }
  }
}
That's why I'm trying to do...
Reply
#6

Not tested.

Try it so:
pawn Код:
enum pinfo
{
    id,
    name[MAX_PLAYER_NAME],
    pass[32]
};

new Var[MAX_PLAYERS][pinfo];

stock ResetPlayerData(playerid)
{
    for(new i = 0; pinfo:i < pinfo; i++)
    {
        switch(i)
        {
          case 0: Var[playerid][pinfo:i] = -1; // Decimal -- enum pinfo id
          case 1..2: Var[playerid][pinfo:i] = EOS; // string -- enum pinfo name, pass,
        }
    }
}
Reply
#7

Quote:
Originally Posted by Phento
Not tested.

Try it so:
pawn Код:
enum pinfo
{
    id,
    name[MAX_PLAYER_NAME],
    pass[32]
};

new Var[MAX_PLAYERS][pinfo];

stock ResetPlayerData(playerid)
{
    for(new i = 0; pinfo:i < pinfo; i++)
    {
        switch(i)
        {
          case 0: Var[playerid][pinfo:i] = -1; // Decimal -- enum pinfo id
          case 1..2: Var[playerid][pinfo:i] = EOS; // string -- enum pinfo name, pass,
        }
    }
}
Amazing!

Thank you so much!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)