SA-MP Forums Archive
Unreachable Codes ? Help me please! - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Unreachable Codes ? Help me please! (/showthread.php?tid=107842)



Unreachable Codes ? Help me please! - Lynax - 11.11.2009

Код:
C:\Documents and Settings\Kerim\Belgelerim\SAMP\gamemodes\LvRoam.pwn(700) : warning 225: unreachable code
C:\Documents and Settings\Kerim\Belgelerim\SAMP\gamemodes\LvRoam.pwn(706) : warning 225: unreachable code
C:\Documents and Settings\Kerim\Belgelerim\SAMP\gamemodes\LvRoam.pwn(712) : warning 225: unreachable code
C:\Documents and Settings\Kerim\Belgelerim\SAMP\gamemodes\LvRoam.pwn(718) : warning 225: unreachable code
C:\Documents and Settings\Kerim\Belgelerim\SAMP\gamemodes\LvRoam.pwn(724) : warning 225: unreachable code
C:\Documents and Settings\Kerim\Belgelerim\SAMP\gamemodes\LvRoam.pwn(731) : warning 225: unreachable code
C:\Documents and Settings\Kerim\Belgelerim\SAMP\gamemodes\LvRoam.pwn(737) : warning 225: unreachable code
C:\Documents and Settings\Kerim\Belgelerim\SAMP\gamemodes\LvRoam.pwn(742) : warning 225: unreachable code
C:\Documents and Settings\Kerim\Belgelerim\SAMP\gamemodes\LvRoam.pwn(748) : warning 225: unreachable code
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


9 Warnings.
http://pastebin.com/m2a58f406

Please help me


Re: Unreachable Codes ? Help me please! - Striker_Moe - 11.11.2009

Remove the return 1; at every command and place one at the end.


Re: Unreachable Codes ? Help me please! - Donny_k - 11.11.2009

It's :

pawn Код:
if ( blah )
{
  //do something here
  return;
}
Not :

pawn Код:
if ( blah )
// do something here
{
  return;
}
The return only exits the function (end the routine), it's the scope which is at fault here.

Edit:

A little explination I thought I'd add.

These two here are valid scopes:

pawn Код:
//one
if ( blah ) //do something here (single line, single instruction)

//two
if ( blah )
  // do something here (single statement, single instruction)
As the compiler has just ran a check (processed a statement) it is expecting to make an instruction but it will only process the next instruction or better said it only links the next instruction (line of code) with that statement unless told otherwise, we use braces (brackets, whatever they are bloody called hehe) to control our scope as the compiler will read from one to the next, it's like start to end, from '{' to '}'.

Although I would stick to the traditional method which runs all instructions inside the scope bounds (the { /*this is my scope*/ }) it is possible to script without them but you have to understand how it works.

pawn Код:
{ //open first scope
  { //open second scope
  } //close second scope
} //close first scope



Re: Unreachable Codes ? Help me please! - (.Aztec); - 11.11.2009

pawn Код:
if (strcmp("/yardim",cmdtext, true,10) == 0)
{
        SendClientMessage(playerid, COLOR_WHITE, "Las Venturas Gelismis FreeRoam");
        SendClientMessage(playerid, COLOR_RED, "---Komutlar---");
        SendClientMessage(playerid, COLOR_BLUE, "/geber - /can - /kalkan - /silahverbana - /anabenmafyaoldum");
        SendClientMessage(playerid, COLOR_BLUE, "/zenginolacamben - /malimben - /yazmabunu - /hergeceiciyorum ");
        SendClientMessage(playerid, COLOR_RED, "---Mod Yapımcısı: Lynax---");
        SendClientMessage(playerid, COLOR_BLUE, "Iletişim: im-here-everytime@hotmail.com");
        return 1;
}
if (strcmp("/anabenmafyaoldum",cmdtext, true,10) == 0)
{
        SendClientMessage(playerid, COLOR_RED, "Anne: Oğlum Mafya Oldu!");
        SetPlayerSkin(playerid, 120);
        return 1;
}
if (strcmp("/geber",cmdtext, true,10) == 0)
{
    SendClientMessage(playerid, COLOR_RED, "Geberdin");
        SetPlayerHealth(playerid, 0);
return 1;
}
if (strcmp("/can",cmdtext, true,10) == 0)
{
        SetPlayerHealth(playerid, 100);
        SendClientMessage(playerid, COLOR_RED, "Canın doldu.");
return 1;
}
if (strcmp("/kalkan",cmdtext, true,10) == 0)
{
        SetPlayerArmour(playerid, 100);
        SendClientMessage(playerid, COLOR_RED, "Kalkan doldu.");
return 1;
}
if (strcmp("/silahverbana",cmdtext, true,10) == 0)
{
    GivePlayerWeapon(playerid, 36, 500);
        GivePlayerWeapon(playerid, 27, 500);
        SendClientMessage(playerid, COLOR_RED, "Silah Aldın.");
return 1;
}
if (strcmp("/zenginolacamben",cmdtext, true,10) == 0)
{
        GivePlayerMoney(playerid, 1);
    SendClientMessage(playerid, COLOR_RED, "Zengin oldun!");
return 1;
}
if (strcmp("/malimben",cmdtext, true,10) == 0)
{
    SetPlayerName(playerid, "MAL");
return 1;
}
if (strcmp("/yazmabunu",cmdtext, true,10) == 0)
{
        SendClientMessage(playerid, COLOR_INDIGO, "Yazma demiyormuyum? Kicklendin! '-.- ");
        Kick(playerid);
return 1;
}
if (strcmp(cmdtext, "/hergeceiciyorum", true) == 0)
{
    SetPlayerDrunkLevel (playerid, 50000);
    SendClientMessage(playerid, 0xFFFFFFAA, "Her gecee iзiyorum! Nedense sızıyorum!");
return 1;
}
return 0;
}
I didn't bother indenting.