#1

pawn Код:
foreach(Player, playerid) {
        if(IsPlayerInForbidZone(playerid) == 1)
        {
            if(PlayerInfo[playerid][Class] == 10 || PlayerInfo[playerid][Class] == 11 || PlayerInfo[playerid][Class] == 12)
            {
               continue;
            }
continue stops the loop from looping. How can i continue loop?
Reply
#2

Not it doesn't, continue moves onto the next set of data in the loop - 'break' stops the loop.

Example:
pawn Код:
for( new i = 0; i < 10; i ++ )
{
   if( i < 5 ) continue;
   printf( "%d", i );
}
// Prints 5, 6, 7, 8, 9
Reply
#3

Quote:
Originally Posted by Grim_
Посмотреть сообщение
Not it doesn't, continue moves onto the next set of data in the loop - 'break' stops the loop.
Well, it doesn't continue looping in my case
Reply
#4

It could be some sort of problem with using it inside of a 'foreach' loop, make sure to double check the documentation regarding it.

It would also help if you showed the code that you tested it with (debugging the problem).
Reply
#5

Quote:
Originally Posted by Grim_
Посмотреть сообщение
It could be some sort of problem with using it inside of a 'foreach' loop, make sure to double check the documentation regarding it.

It would also help if you showed the code that you tested it with (debugging the problem).
pawn Код:
foreach(Player, playerid) {
        if(IsPlayerInForbidZone(playerid) == 1)
        {
         if(PlayerInfo[playerid][Class] == 10 || PlayerInfo[playerid][Class] == 11 || PlayerInfo[playerid][Class] == 12)
         {
           continue;
         }
           if(GetPVarInt(playerid, "ENTERED") == 0) {
            SetPVarInt(playerid, "ENTERED", 1);
            SetPVarInt(playerid, "LEAVE_TIME", randomEx(15, 30));
           }
           if(GetPVarInt(playerid, "ENTERED") == 1 && GetPVarInt(playerid, "LEAVE_TIME") > 0) {
              SetPVarInt(playerid, "LEAVE_TIME", GetPVarInt(playerid, "LEAVE_TIME") -1);
              format(String, sizeof(String), LoadText(playerid, "WARNING_TEXT"), GetPVarInt(playerid, "LEAVE_TIME"));
              GameTextForPlayer(playerid, String, 4000, 3);
           }
           if(GetPVarInt(playerid, "LEAVE_TIME") == 0) {
              PlayerInfo[playerid][WantedLevel] += 8;
              SetPVarInt(playerid, "LEAVE_TIME", -1);
              GameTextForPlayer(playerid, LoadText(playerid, "SHOOT_NOW"), 3000, 3);
           }
        }
}
IsPlayerInForbidZone returns 1 if i am in the zone , maybe thats the problem?
EDIT: Debugged, it stops right after continue;
Reply
#6

Are you the only player on the server? If so, it's obviously going to stop after the first loop. Foreach only loops through the connected player IDs.

The problem persists because this line is true, making the loop to continue (which, in this case, it's at the end)
pawn Код:
if(PlayerInfo[playerid][Class] == 10 || PlayerInfo[playerid][Class] == 11 || PlayerInfo[playerid][Class] == 12)
Reply
#7

Quote:
Originally Posted by Grim_
Посмотреть сообщение
Are you the only player on the server? If so, it's obviously going to stop after the first loop. Foreach only loops through the connected player IDs.

The problem persists because this line is true, making the loop to continue (which, in this case, it's at the end)
pawn Код:
if(PlayerInfo[playerid][Class] == 10 || PlayerInfo[playerid][Class] == 11 || PlayerInfo[playerid][Class] == 12)
i didn't post everything what i had under the loop, i have many more functions under the loop including the function what i showed you, i just posted needed code.
Reply
#8

That doesn't change anything as long as that's the only 'continue' statement in the loop. It's being called after that line, and if it's true, and you're the only player on the server, it's going to not loop anymore.

I would suggest you read more documentation on Foreach and loops overall more on the SA:MP Wiki.
Reply
#9

fixed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)