SA-MP Forums Archive
loop - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: loop (/showthread.php?tid=205444)



loop - armyoftwo - 01.01.2011

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?


Re: loop - Grim_ - 01.01.2011

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



Re: loop - armyoftwo - 01.01.2011

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


Re: loop - Grim_ - 01.01.2011

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).


Re: loop - armyoftwo - 01.01.2011

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;


Re: loop - Grim_ - 01.01.2011

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)



Re: loop - armyoftwo - 01.01.2011

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.


Re: loop - Grim_ - 01.01.2011

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.


Re: loop - armyoftwo - 01.01.2011

fixed