Fuck my life </3
#1

Unreachable code on
Код:
if((slot == 2) && (PlayerInfo[playerid][pCKey2] != 255))
pawn Код:
if((slot == 1) && (PlayerInfo[playerid][pCKey] != 255))
{
SendClientMessage(playerid, COLOR_RED, "That car key slot is full! Choose a different slot (1/2) or sell your car!");
return 1;
}
else
{
CInfo[carid][cBought] = 1;
PlayerInfo[playerid][pCKey] = carid+1;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(CInfo[carid][cOwner], sendername, 0, strlen(sendername), 255);
AntiHack(playerid,-CInfo[carid][cValue]);
SendClientMessage(playerid, COLOR_GREEN, "Success. You have purchased this car into slot [1], type /carinfo [key slot]");
OnPropUpdate();
return 1;
}
if((slot == 2) && (PlayerInfo[playerid][pCKey2] != 255))
{
SendClientMessage(playerid, COLOR_RED, "That car key slot is full! Choose a different slot (1/2) or sell your car!");
return 1;
}
else
{
CInfo[carid][cBought] = 1;
PlayerInfo[playerid][pCKey2] = carid+1;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(CInfo[carid][cOwner], sendername, 0, strlen(sendername), 255);
AntiHack(playerid,-CInfo[carid][cValue]);
SendClientMessage(playerid, COLOR_GREEN, "Success. You have purchased this car into slot [2], type /carinfo [key slot]");
OnPropUpdate();
return 1;
}
}
Reply
#2

Why not
pawn Код:
if(slot == 2 && PlayerInfo[playerid][pCKey2] != 255)
Also, what's the lines before that?
Reply
#3

Here your code (cutted some parts out)

pawn Код:
if(slot == 1) return 1;
else return 1;
if(slot == 2) return 1; //unreachable
else return 1;
Reason should be clear
Reply
#4

Quote:
Originally Posted by [HiC
TheKiller ]
Why not
pawn Код:
if(slot == 2 && PlayerInfo[playerid][pCKey2] != 255)
That keeps the 2 'if' together, doesn't screw it up.

Quote:
Originally Posted by [HiC
TheKiller ]

Also, what's the lines before that?
Its the rest of my /buycar command, but I don't want to give it away. Don't worry, it isn't causing any errors.
Reply
#5

Quote:
Originally Posted by ♣ Joker ♠
Here your code (cutted some parts out)

pawn Код:
if(slot == 1) return 1;
else return 1;
if(slot == 2) return 1; //unreachable
else return 1;
Reason should be clear
Sorry for double, but the reason ISNT clear -.-
Reply
#6

Quote:
Originally Posted by Antonio (eternalrp.webatu.com)
Quote:
Originally Posted by ♣ Joker ♠
Here your code (cutted some parts out)

pawn Код:
if(slot == 1) return 1;
else return 1;
if(slot == 2) return 1; //unreachable
else return 1;
Reason should be clear
Sorry for double, but the reason ISNT clear -.-
A return stops the rest of the code after it from executing. Take this example:
pawn Код:
if(1 == 2) return 1;
else return 1;
// Everything after this cannot be reached
Why? Well, because you have it that if '1' equals '2', then it'll return. And then if it's else (doesn't equal 2) you still have it returning.
Reply
#7

Huh?

So just remove the returns?
Reply
#8

Quote:
Originally Posted by Antonio (eternalrp.webatu.com)
Huh?

So just remove the returns?
Well, what do you want the script to do if slot equals 1 and what do you want it to do if slot equals 2?
Reply
#9

pawn Код:
if(slot == 1 || slot == 2) { //Not needed if you only have slot 1 and slot 2
    if(PlayerInfo[playerid][pCKey] != 255) {
        SendClientMessage(playerid, COLOR_RED, "That car key slot is full! Choose a different slot (1/2) or sell your car!");
    } else {
        if(slot == 1) {
            PlayerInfo[playerid][pCKey] = carid+1; //you could have used an array for pCKey, too
            SendClientMessage(playerid, COLOR_GREEN, "Success. You have purchased this car into slot [1], type /carinfo [key slot]");
        } else {
            PlayerInfo[playerid][pCKey2] = carid+1;
            SendClientMessage(playerid, COLOR_GREEN, "Success. You have purchased this car into slot [2], type /carinfo [key slot]");
        }
        CInfo[carid][cBought] = 1;
        GetPlayerName(playerid, sendername, sizeof(sendername));
        strmid(CInfo[carid][cOwner], sendername, 0, strlen(sendername), 255);
        AntiHack(playerid,-CInfo[carid][cValue]);
        OnPropUpdate();
    }
}
Reply
#10

Quote:
Originally Posted by Antonio (eternalrp.webatu.com)
Its the rest of my /buycar command, but I don't want to give it away. Don't worry, it isn't causing any errors.
How do you know?

Because that's the code that's causing errors, because there is a return somewhere that stops the code you posted here from being executed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)