SA-MP Forums Archive
Error loop run out of limit - 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: Error loop run out of limit (/showthread.php?tid=581160)



Error loop run out of limit - meocahat - 11.07.2015

I made the code:
Код:
CMD:deleteallhouseex(playerid, params[])
{
	for(new i = 0; i < 5001; i++)
	{
	    HouseInfo[i][hLevel] = 0;
	    HouseInfo[i][hCustomInterior] = 0;
	    HouseInfo[i][hDescription] = 0;
	    format(HouseInfo[i][hOwnerName],MAX_PLAYER_NAME, "Nobody");
	    HouseInfo[i][hExteriorX] = 0;
	    HouseInfo[i][hExteriorY] = 0;
	    HouseInfo[i][hExteriorZ] = 0;
	    HouseInfo[i][hExteriorR] = 0;
	    HouseInfo[i][hExteriorA] = 0;
	    HouseInfo[i][hLock] = 0;
	    HouseInfo[i][hRentable] = 0;
	    HouseInfo[i][hRentFee] = 0;
	    HouseInfo[i][hValue] = 0;
	    ClearHouse(i);
	    DestroyDynamicPickup(HouseInfo[i][hPickupID]);
	    DestroyDynamic3DTextLabel(HouseInfo[i][hTextID]);
	    HouseInfo[i][hCustomExterior] = 0;
	    SaveHouses();
	}
	SendClientMessage(playerid, COLOR_YELLOW, "All house deleted.");
	return 1;
}
When i run this command, the houses isn't delete. Then, the Console print this Message:
Код:
Saving House ID 0
Saving House ID 1
...
Saving House ID 4999
Saving House ID 0
Saving House ID 1
...
So, what was wrong with that loop ? How to fix ?


Re: Error loop run out of limit - Prokill911 - 11.07.2015

Okay so lets take a look..

Firstly, You're saying..
i = 0..
While i < 5001
Count++,

You're then getting House Info[i]
i = 0..

You're basically telling it to destroy ID's that don't exist..

So It's looking through all "HouseInfo[i]"
an If It doesn't find a house that matches [i]..
It will stop an skip to the end...

You should define the maximum number of houses when a player logs in...
So when your server starts up..
It should count each house an assign an ID.
then you call the house ID its self..

So try this...
PHP код:
for(new 0HouseInfoi++) { 
That's just guess code..
because I have no way of knowing how your enum / array structure is setup.


Re: Error loop run out of limit - DarkLouis - 11.07.2015

No. The correct code's this.

PHP код:
for(new 0sizeof(HouseInfo); i++) 
Tested and worked.


Re : Error loop run out of limit - KillerDVX - 11.07.2015

[I]This should works :

PHP код:
CMD:deleteallhouseex(playeridparams[])
{
    for(new 
0sizeof(HouseInfo); i++)
    {
        
HouseInfo[i][hLevel] = 0;
        
HouseInfo[i][hCustomInterior] = 0;
        
HouseInfo[i][hDescription] = 0;
        
format(HouseInfo[i][hOwnerName],MAX_PLAYER_NAME"Nobody");
        
HouseInfo[i][hExteriorX] = 0;
        
HouseInfo[i][hExteriorY] = 0;
        
HouseInfo[i][hExteriorZ] = 0;
        
HouseInfo[i][hExteriorR] = 0;
        
HouseInfo[i][hExteriorA] = 0;
        
HouseInfo[i][hLock] = 0;
        
HouseInfo[i][hRentable] = 0;
        
HouseInfo[i][hRentFee] = 0;
        
HouseInfo[i][hValue] = 0;
        
ClearHouse(i);
        
DestroyDynamicPickup(HouseInfo[i][hPickupID]);
        
DestroyDynamic3DTextLabel(HouseInfo[i][hTextID]);
        
HouseInfo[i][hCustomExterior] = 0;
        
SaveHouses();
    }
    
SendClientMessage(playeridCOLOR_YELLOW"All house deleted.");
    return 
1;
}[/
i


KillerDVX,



Re: Error loop run out of limit - meocahat - 11.07.2015

Thank you guys so much


Re: Error loop run out of limit - liquor - 11.07.2015

But... If SaveHouses(); also is a loop through all houses, this code is very bad for server performance... Put SaveHouses(); outside the loop...