Unreachable code fix? +REP
#5

What you did wrong.
pawn Код:
if(strcmp("/closetank47", cmdtext, false, 10) == 0)
{
    // if the player is in range of the point
    if(IsPlayerInRangeOfPoint(playerid, 2, 652.20001220703, -1506.3000488281, 23.5))
    {
        // this code will be ran
        SendClientMessage(playerid, 0x10F441AA, "Tank Closed!");
        Create3DTextLabel("Tank Closed!", 0x10F441AA, 658.70001220703, -1507.5999755859, 22, 40.0, 0, 1);
       
        // and returning 1 here stops the rest of the command from processing
        return 1;
    }
    // if the player is not in range of the point
    else
    {
        // this code is ran
        SendClientMessage(playerid, 0xAFAFAFAA, "Get Closer to the Tank!");
        // and returning 1 here stops the code
        return 1;
    }
    // since both statements stop the rest of the command
    // the code below will never be reachable, that explains the "unreachable code" error.
    return 1;
}
So the correct way would be.
pawn Код:
if(strcmp("/closetank47", cmdtext, false, 10) == 0)
{
    if(IsPlayerInRangeOfPoint(playerid, 2, 652.20001220703, -1506.3000488281, 23.5))
    {
        SendClientMessage(playerid, 0x10F441AA, "Tank Closed!");
        Create3DTextLabel("Tank Closed!", 0x10F441AA, 658.70001220703, -1507.5999755859, 22, 40.0, 0, 1);
        return 1;
    }
    else
    {
        SendClientMessage(playerid, 0xAFAFAFAA, "Get Closer to the Tank!");
    }
    return 1;
}
Reply


Messages In This Thread
Unreachable code fix? +REP - by ShawtyyMacJunior - 30.07.2012, 06:18
Re: Unreachable code fix? +REP - by Devilxz97 - 30.07.2012, 06:21
Re: Unreachable code fix? +REP - by newbienoob - 30.07.2012, 06:21
Re: Unreachable code fix? +REP - by Cjgogo - 30.07.2012, 06:22
Re: Unreachable code fix? +REP - by ReneG - 30.07.2012, 06:38

Forum Jump:


Users browsing this thread: 4 Guest(s)