Loops only run one function?
#1

pawn Код:
stock CheckHouse(playerid)
{
    if(PlayerInfo[playerid][pInHouse] >= 0)
    {
        for(new idx = 0; idx < MAX_HOUSES; idx++)
        {
            if(!strcmp(PlayerInfo[playerid][pInAddress], HouseInfo[idx][hAddress], false))
            {
                SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], HouseInfo[idx][hExitPos][0], HouseInfo[idx][hExitPos][1], HouseInfo[idx][hExitPos][2], HouseInfo[idx][hExitPos][3], 0, 0, 0, 0, 0, 0);
                SetPlayerPos(playerid, HouseInfo[idx][hExitPos][0], HouseInfo[idx][hExitPos][1], HouseInfo[idx][hExitPos][2]);
                SetPlayerFacingAngle(playerid, HouseInfo[idx][hExitPos][3]);
                SetInterior(playerid, HouseInfo[idx][hInterior]);
                SetVirtualWorld(playerid, HouseInfo[idx][hVirtualWorld]);
                PlayerInfo[playerid][pInHouse] = HouseInfo[idx][hHouseID];
                format(PlayerInfo[playerid][pInAddress], 32, "%s", HouseInfo[idx][hAddress]);
                break;
            }
            if(strcmp(PlayerInfo[playerid][pInAddress], HouseInfo[idx][hAddress], false))
            {
                SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], -2656.6123, 635.8759, 14.4531, 182.7413, 0, 0, 0, 0, 0, 0);
                SetPlayerPos(playerid, -2656.6123, 635.8759, 14.4531);
                SetPlayerFacingAngle(playerid, 182.7413);
                SetInterior(playerid, 0);
                SetVirtualWorld(playerid, 0);
                PlayerInfo[playerid][pInHouse] = -1;
                format(PlayerInfo[playerid][pInAddress], 32, "None");
                SendClientMessage(playerid, COLOR_ORANGE, "The house you were in has been edited or deleted. You have been set back to the newb spawn.");
                break;
            }
        }
    }
    else
    {
        SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pPos][0], PlayerInfo[playerid][pPos][1], PlayerInfo[playerid][pPos][2], PlayerInfo[playerid][pPos][3], 0, 0, 0, 0, 0, 0);
        SetPlayerPos(playerid, PlayerInfo[playerid][pPos][0], PlayerInfo[playerid][pPos][1], PlayerInfo[playerid][pPos][2]);
        SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPos][3]);
        SetInterior(playerid, PlayerInfo[playerid][pInterior]);
        SetVirtualWorld(playerid, PlayerInfo[playerid][pVirtualWorld]);
        format(PlayerInfo[playerid][pInAddress], 32, "None");
    }
    return 1;
}
Very close to completing my housing system, last problem I have..
If I remove the second "if", the first one works, if I keep it, only the second one works.
Can I not use two different "if" functions inside a loop?
Reply
#2

I'm very tired so please bare with me.

If I understand correctly, I think "break;" causes your loop to stop completely. Either removing "break;" or changing the second "if" to "else if" may fix it.

If you want to break the loop regardless, I suggest placing the break; statement outside any "if" statement. (i.e. before the closing callback of the loop).

Sorry if I don't make alot of sense, would appreciate someone else either rephrasing my words or correcting them.
Reply
#3

Use else, not that that matters, and remove the breaks.
Reply
#4

Thanks guys, managed to find a work around. Removing break and adding else didn't work. Would have been better if it worked this way though
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)