Unreachable Code!
#1

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
Reply
#2

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
Reply
#3

it's the same, you have done nothin', it's the same!
Reply
#4

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 { }).
Reply
#5

Or do it like this:

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

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
Reply
#7

Thanks all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)