SA-MP Forums Archive
Unreachable Code! - 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: Unreachable Code! (/showthread.php?tid=353798)



Unreachable Code! - Youice - 24.06.2012

Hello,

I have created this code but IDK why I'm receiving a warning?

Here is the code::

Код:
CMD:setringtone(playerid, params[])
{
    new
		value,
    	str[295],
		string[295],
 		pname[MAX_PLAYER_NAME]
	;
	GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
	if(PlayerInfo[playerid][pWrestler] >= 1)
	{
	    if(sscanf(params, "s", value)) SendClientMessage(playerid, -1, "Syntax: /setringtone [url/ringotne]");                              SendClientMessage(playerid, -1, "For Example: http://YOUR_URL_OF_THE_SONG"); return true;
        PlayerInfo[playerid][pRingTone] = value; //<<< unreachable code
Here is the warning::

Код:
warning 225: unreachable code



Re: Unreachable Code! - Euan Hughes - 24.06.2012

pawn Код:
CMD:setringtone(playerid, params[])
{
    new
        value,
        str[295],
        string[295],
        pname[MAX_PLAYER_NAME]
    ;
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
    if(PlayerInfo[playerid][pWrestler] >= 1)
    {
        if(sscanf(params, "s", value))
           {
                    SendClientMessage(playerid, -1, "Syntax: /setringtone [url/ringotne]");                                                                                         SendClientMessage(playerid, -1, "For Example: http://YOUR_URL_OF_THE_SONG");
}
        PlayerInfo[playerid][pRingTone] = value; //<<< unreachable code
Try that


Re: Unreachable Code! - Youice - 24.06.2012

it's the same, you have done nothin', it's the same!


Re: Unreachable Code! - Badger(new) - 24.06.2012

You've got some extra code on the sscanf line which isn't surrounded by { }.

Replace this:
pawn Код:
if(sscanf(params, "s", value)) SendClientMessage(playerid, -1, "Syntax: /setringtone [url/ringotne]");                              SendClientMessage(playerid, -1, "For Example: http://YOUR_URL_OF_THE_SONG"); return true;
with this:
pawn Код:
if(sscanf(params, "s", value)){
    SendClientMessage(playerid, -1, "Syntax: /setringtone [url/ringotne]");
    SendClientMessage(playerid, -1, "For Example: http://YOUR_URL_OF_THE_SONG");
    return true;
}

Additional:

The unreachable code error basically means the line of code it is referencing cannot be accessed because of something BEFORE that line of code (e.g. you return a value for the callback/function or you mis-use { }).


Re: Unreachable Code! - Kindred - 24.06.2012

Or do it like this:

pawn Код:
if(sscanf(params, "s", value)) return SendClientMessage(playerid, -1, "Syntax: /setringtone [url/ringotne]");



Re: Unreachable Code! - Babul - 24.06.2012

one rule i never break, is:
Код:
if (you write an "if" in your script)
{
	fuckin' indent. your TAB key is not that [        ] fat to be ignored.
}
mkay, with some exceptions, like code which will never be touched anymore - its easier to end with 1 line when collapsing callbacks/other nested lines
look at a simple toggle command, the 1st 3rd line got the { bracket at the end. bad practise, but you get the point, when you see the "fake" collapsed code (in fact: how it looks to me)...
the full thing:
pawn Код:
CMD:insert(playerid,cmdtext[]){
    InsertMode=1-InsertMode;
    switch(InsertMode){
        case 0:
        {
            SendClientMessage(playerid,MSGCMDS_COLOR,"Insertion Mode {ffaaaa}disabled");
        }
        case 1:
        {
            SendClientMessage(playerid,MSGCMDS_COLOR,"Insertion Mode {aaffaa}enabled");
        }
    }
    return 1;
}
collapsed the switch-line (imagine a + symbol indicating a collapsed line, so the [ only is ok here:
pawn Код:
CMD:insert(playerid,cmdtext[]){
    InsertMode=1-InsertMode;
    switch(InsertMode){ //nested, collapsed stuff inside
    return 1;
}
i promise, if you nest each single line, and indent your code, you will never fail at such shit again.

edit: oh, here's your code, i changed "nothing" except swapping 2 lines and copying 1 hehe
pawn Код:
CMD:setringtone(playerid, params[])
{
    new
    value,
    str[295],
    string[295],
    pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
    if(PlayerInfo[playerid][pWrestler] >= 1)
    {
        if(sscanf(params, "s", value))
        {
            SendClientMessage(playerid, -1, "Syntax: /setringtone [url/ringotne]");
            SendClientMessage(playerid, -1, "For Example: http://YOUR_URL_OF_THE_SONG");
            PlayerInfo[playerid][pRingTone] = value; //<<< fixed
            return true;//this line could be deleted for now, below is another one. but if theres some stuff you want to be done incase the wrestler- or value-check fails, that line should stay.
        }
    }
    return true;
}
edit2:
may i ask what the ringtones are? numerical values or strings for streaming audio? or both? since the value is a single cell, its a good idea to change the sscanf specifier from "s" to "d" maybe? what if the player inputs a string? then the value is indeed a string:
pawn Код:
value[128]
.. and makes the specifier change obsolete.. argh


Re: Unreachable Code! - Youice - 25.06.2012

Thanks all