SA-MP Forums Archive
Problem with a loop - 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: Problem with a loop (/showthread.php?tid=595728)



Problem with a loop - TwinkiDaBoss - 07.12.2015

------


Re: Problem with a loop - PaulDinam - 07.12.2015

Your for loop max value is MAX_HOUSES, simply change <= MAX_HOUSES to < MAX_HOUSES.

One more thing that has caught my attention, what if not all 255 houses are being used? You need to check if the house exists.

pawn Код:
SaveAllHouses()
{
    new HousesSaved = 0, query[600];
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(HouseInfo[i][HID] != 0)
        {
            mysql_format(mysql, query, sizeof(query), "UPDATE `houses` SET `Price` = %d, `EnterX` = %f ,`EnterY` = %f, `EnterZ` = %f, `ExitX` = %f, `ExitY` = %f, `ExitZ` = %f, `Owned` = %d, `Locked` = %d, `HouseBank` = %d WHERE `ID`= %d",\
            HouseInfo[i][HousePrice],HouseInfo[i][EnterX],HouseInfo[i][EnterY],HouseInfo[i][EnterZ],HouseInfo[i][ExitX],HouseInfo[i][ExitY],HouseInfo[i][ExitZ],HouseInfo[i][Owned],HouseInfo[i][Locked],HouseInfo[i][HouseBank],HouseInfo[i][HID]);
            mysql_pquery(mysql, query);
            HousesSaved++;
        }
    }
    printf("Total of %i houses saved",HousesSaved);
}
Your query was wrong as well.


Re: Problem with a loop - TwinkiDaBoss - 07.12.2015

Hmm I think I should get some sleep seriously haha.

Thanks lad +rep of course