foreach errors - 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)
+--- Thread: foreach errors (
/showthread.php?tid=495605)
foreach errors -
Aerotactics - 18.02.2014
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:
Код:
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.
Re: foreach errors -
Dubya - 18.02.2014
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;
}
Re: foreach errors -
Aerotactics - 18.02.2014
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
Re: foreach errors -
Scenario - 18.02.2014
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.
Re: foreach errors -
Scaleta - 18.02.2014
This usage should work
pawn Код:
foreach(Player, i) {
//code here
}
or you could just use the normal
for loop.