foreach errors
#1

When I tried to use foreach by Y-less in my map script I got these errors:
Код:
C:\Users\Aerotactics' PC\Desktop\ALSRP\filterscripts\LSRPMap.pwn(83) : error 017: undefined symbol "foreach"
C:\Users\Aerotactics' PC\Desktop\ALSRP\filterscripts\LSRPMap.pwn(83) : error 029: invalid expression, assumed zero
C:\Users\Aerotactics' PC\Desktop\ALSRP\filterscripts\LSRPMap.pwn(83) : error 017: undefined symbol "i"
C:\Users\Aerotactics' PC\Desktop\ALSRP\filterscripts\LSRPMap.pwn(83) : fatal error 107: too many error messages on one line
And here's my script:
Код:
#include <foreach>
Код:
	foreach (new i : Player) <--Line 83
	{
		RemoveBuildingForPlayer(i,3605,1497.85938,-674.82812,99.88281,31.681875228882);
		RemoveBuildingForPlayer(i,3604,1525.5,-691.69531,96.07813,11.981899261475);
	}
Before I tried just using playerid in place of "i" without any foreach scripting involved and got an output that said "playerid isn't valid" or something along those lines.
Reply
#2

i get the feeling that you're doing this in OnGameModeInit:
RemoveBuildingForPlayer has no effect in OnGameModeInit.

Call it in OnPlayerConnect: foreach isn't needed.
pawn Код:
public OnPlayerConnect(playerid)
{
    RemoveBuildingForPlayer(playerid,3605,1497.85938,-674.82812,99.88281,31.681875228882);
    RemoveBuildingForPlayer(playerid,3604,1525.5,-691.69531,96.07813,11.981899261475);

    // Rest of code
    return 1;
}
Reply
#3

Quote:
Originally Posted by Dubya
Посмотреть сообщение
i get the feeling that you're doing this in OnGameModeInit:
RemoveBuildingForPlayer has no effect in OnGameModeInit.

Call it in OnPlayerConnect: foreach isn't needed.
pawn Код:
public OnPlayerConnect(playerid)
{
    RemoveBuildingForPlayer(playerid,3605,1497.85938,-674.82812,99.88281,31.681875228882);
    RemoveBuildingForPlayer(playerid,3604,1525.5,-691.69531,96.07813,11.981899261475);

    // Rest of code
    return 1;
}
OH that makes sense, thank you. And yes I have it under GM Init cause thats where object and car spawns are lol
Reply
#4

Well, foreach wouldn't work there anyways. The Player iterator only contains a list of CONNECTED player IDs, and since nobody is actually connected when the game-mode starts... the list is empty. You should use a for() loop for that instead...

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
Nevertheless, make sure you're using the correct foreach version for that foreach(new i : Player) syntax- that wasn't the original one.
Reply
#5

This usage should work

pawn Код:
foreach(Player, i) {
    //code here
}
or you could just use the normal for loop.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)