SA-MP Forums Archive
When to use 'else'... - 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: When to use 'else'... (/showthread.php?tid=382380)



When to use 'else'... - angus_31 - 03.10.2012

Can someone tell me when to use else for this situation I'm in.
Quote:

case 0:
{
SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
GivePlayerMoney(playerid, -100);
SendClientMessage(playerid, COLOR_WHITE, "You've learnt Boxing!");
}

I want to use else so if they don't have enough money it will say "You don't have enough money!", please help.


Re: When to use 'else'... - RedJohn - 03.10.2012

pawn Код:
case 0:
{
    if(GetPlayerMoney(playerid) < 100) return SendClientMessage(playerd, RED, "You don't have enough money!");
    SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
    GivePlayerMoney(playerid, -100);
    SendClientMessage(playerid, COLOR_WHITE, "You've learnt Boxing!");
}
Or..

pawn Код:
case 0:
{
    if(GetPlayerMoney(playerid) > 100)
    {
        SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
        GivePlayerMoney(playerid, -100);
        SendClientMessage(playerid, COLOR_WHITE, "You've learnt Boxing!");
    }
    else SendClientMessage(playerd, RED, "You don't have enough money!");
}



Re: When to use 'else'... - angus_31 - 03.10.2012

Thanks a lot, repped.