Error loop run out of limit
#1

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 ?
Reply
#2

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

No. The correct code's this.

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

[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,
Reply
#5

Thank you guys so much
Reply
#6

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


Forum Jump:


Users browsing this thread: 2 Guest(s)