SA-MP Forums Archive
Looping problem - 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: Looping problem (/showthread.php?tid=290347)



Looping problem - Jack_Leslie - 15.10.2011

Hi Guys,

I have this code right here:
pawn Код:
if(PlayerInfo[i][HouseID] != 0)
        { //owns house or business
            GiveMoney(i,-250);
            format(string, sizeof(string), "  Electricity Bill: -$250");
            SendClientMessage(i, COLOR_GRAD1, string);
            if(HouseInfo[PlayerInfo[i][HouseID]][hRentable] == 1)
            {
                for(new z = 0; z <= MAX_PLAYERS; z++)
                {
                    if(PlayerInfo[z][RentingID] == PlayerInfo[i][HouseID])
                    {
                        RentIncome[i] += HouseInfo[PlayerInfo[i][HouseID]][hRentPrice];
                        break;
                    }
               }
                GiveMoney(i, RentIncome[i]);
                format(string, sizeof(string),"  Rent Income: $%d", RentIncome[i]);
                SendClientMessage(i, COLOR_GRAD1, string);
                RentIncome[i] = 0;
            }
        }

It half works. This bit however:
pawn Код:
for(new z = 0; z <= MAX_PLAYERS; z++)
                {
                    if(PlayerInfo[z][RentingID] == PlayerInfo[i][HouseID])
                    {
                        RentIncome[i] += HouseInfo[PlayerInfo[i][HouseID]][hRentPrice];
                        break;
                    }
               }
Is meant to increase RentIncome EACH TIME it finds a match. How ever, it just increases it by one the first time it finds a match. If rentingid == houseid it should increase and then keep checking until it reaches the end of "MAX_PLAYERS". But it stops at the first match and doesn't continue to raise RentIncome.


Re: Looping problem - playbox12 - 15.10.2011

That is because you break the loop, remove break;


Re: Looping problem - Jack_Leslie - 15.10.2011

Quote:
Originally Posted by playbox12
Посмотреть сообщение
That is because you break the loop, remove break;
Thanks! Can't test it at the moment but that makes sense. I thought break; did the opposite (kept it going).