Looping problem
#1

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

That is because you break the loop, remove break;
Reply
#3

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).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)