SA-MP Forums Archive
"For" loop breaking a command? - 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: "For" loop breaking a command? (/showthread.php?tid=268294)



"For" loop breaking a command? - dowster - 12.07.2011

I have a command to create a house pickup, and when i have the for loop in it the game displays "Server: Unknown command" however with the loop commented out it works. Anyone know whats wrong here? Even if you don't know just comment saying IDk, so i know if i should give up with the loop or not.

Код:
CMD:chouse(playerid)
{
	new hID;
	if(gPlayerData[playerid][ADMINLEVEL] < 1)return 1;
	for (new i = 0; i <= MAX_HOUSES; i++)
	{
		if(gHouseData[i][EXIST] != 0)
		{
			hID++;
		}
		else
		{
			continue;
		}	
	}
	GetPlayerPos( playerid, gHouseData[hID][LOCX], gHouseData[hID][LOCY], gHouseData[hID][LOCZ]);
	CreateDynamicPickup( 1237, 1, gHouseData[hID][LOCX], gHouseData[hID][LOCY], gHouseData[hID][LOCZ], -1, -1, -1);
	gPlayerData[playerid][CHOUSEID] = hID;
	gHouseData[hID][EXIST] = 1;
	SendClientMessage(playerid, COLOR_WHITE, "WTH");
	return 1;
}



Re: "For" loop breaking a command? - PotH3Ad - 12.07.2011

It's most likely this line:

pawn Код:
gHouseData[i][EXIST] != 0
If you call any number greater then the array size, it will break the code. (I suck at explaining things)

Try replacing this line:
pawn Код:
for(new i = 0; i<MAX_HOUSES; i++)
I get this problem a lot.


Re: "For" loop breaking a command? - dowster - 14.07.2011

Thanks, will try once i get this code back in lol.. im rebuilding my curropt game mode from my forum posts lol