"For" loop breaking a command?
#1

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;
}
Reply
#2

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.
Reply
#3

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


Forum Jump:


Users browsing this thread: 1 Guest(s)