SA-MP Forums Archive
Help me here - 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: Help me here (/showthread.php?tid=241755)



Help me here - Soumi - 18.03.2011

Well , when i compile the .pwn file i get this error


Код:
(578) : warning 225: unreachable code
This is the command :

//Kick cmd :
Код:
    if(!strcmp(cmd, "/kick"))
    {
  {
  if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFFFFFFFF,"You are not an admin !");
  new targetid, reason[64], string[128];
  if(sscanf(params, "uz", targetid, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /kick [playerid/partofname] [reason]");
  if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFFF, "Player not connected!");
  else
  {
  new pName[128];
  GetPlayerName(targetid,pName,128);
  format(string, sizeof(string), "%s have been Muted By an Admin ! Reason: %s", pName, reason);
  SendClientMessageToAll(0xA10000AA,string);
  format(string, sizeof(string), "You have been kicked! Reason: %s", reason);
  SendClientMessage(targetid,0xA10000AA,string);
  Kick(targetid);
  }
  return 1;
}
  return 1;
}



Re: Help me here - Roomeo - 18.03.2011

Forums bug Double Post


Re: Help me here - Roomeo - 18.03.2011

what is the line 578?


Re : Help me here - Soumi - 18.03.2011

return 1;
}

the second return


Re: Help me here - Markx - 18.03.2011

pawn Код:
if(!strcmp(cmd, "/kick"))
    {
  {
  if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFFFFFFFF,"You are not an admin !");
  new targetid, reason[64], string[128];
  if(sscanf(params, "uz", targetid, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /kick [playerid/partofname] [reason]");
  if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFFF, "Player not connected!");
  else
  {
  new pName[128];
  GetPlayerName(targetid,pName,128);
  format(string, sizeof(string), "%s have been Muted By an Admin ! Reason: %s", pName, reason);
  SendClientMessageToAll(0xA10000AA,string);
  format(string, sizeof(string), "You have been kicked! Reason: %s", reason);
  SendClientMessage(targetid,0xA10000AA,string);
  Kick(targetid);
  }
}
  return 1;
}
indentitation failed on forum.


Re: Help me here - alpha500delta - 18.03.2011

Remove 2nd return 1 I guess?


Re: Help me here - JaTochNietDan - 18.03.2011

The error means that the piece of code will never possibly be reached. The last return in that code can never be reached, because there is no logical path to where it can be reached, the code is always stopped before it. So either remove it, or else re-structure the code. Additionally you have two un-needed brackets in the snippet.


Re: Help me here - maramizo - 18.03.2011

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
The error means that the piece of code will never possibly be reached. The last return in that code can never be reached, because there is no logical path to where it can be reached, the code is always stopped before it. So either remove it, or else re-structure the code. Additionally you have two un-needed brackets in the snippet.
There really was no reed to write all that... Lol.
@OP :
If you use "else", you shouldn't really be using return 1; at the end, because ELSE includes EVERYTHING other than the IF earlier stated.


Re: Help me here - JaTochNietDan - 18.03.2011

Quote:
Originally Posted by maramizo
Посмотреть сообщение
There really was no reed to write all that... Lol.
@OP :
If you use "else", you shouldn't really be using return 1; at the end, because ELSE includes EVERYTHING other than the IF earlier stated.
Why not? Obviously he doesn't know what the error means, so instead of providing him with a quick fix, why not explain to him what the error means, and then he can fix it himself and learn something new? Then he won't have to rely on other people to solve it for him in the future if it happens again.

Quote:
Originally Posted by Schurman
Посмотреть сообщение
pawn Код:
if(!strcmp(cmd, "/kick")
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFFFFFFFF,"You are not an admin !");
    new targetid, reason[64], string[128];
    if(sscanf(params, "uz", targetid, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /kick  [playerid/partofname] [reason]");
    if(!IsPlayerConnected(targetid))
    {
        SendClientMessage(playerid,0xFFFFFFFF,"Player not connected!");
    }
    else
    {
        new pName[128];
        GetPlayerName(targetid,pName,128);
        format(string, sizeof(string), "%s have been Muted By an Admin ! Reason: %s", pName, reason);
        SendClientMessageToAll(0xA10000AA,string);
        format(string, sizeof(string), "You have been kicked! Reason: %s", reason);
        SendClientMessage(targetid,0xA10000AA,string);
        Kick(targetid);
        return 1;
   }
}
There's a problem with that structure too, should the player not be connected, the code will continue down past the command. So I would suggest putting the return 1 outside of the else statement. Like so:

pawn Код:
if(!strcmp(cmd, "/kick")
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFFFFFFFF,"You are not an admin !");
    new targetid, reason[64], string[128];
    if(sscanf(params, "uz", targetid, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /kick  [playerid/partofname] [reason]");
    if(!IsPlayerConnected(targetid))
    {
        SendClientMessage(playerid,0xFFFFFFFF,"Player not connected!");
    }
    else
    {
        new pName[128];
        GetPlayerName(targetid,pName,128);
        format(string, sizeof(string), "%s have been Muted By an Admin ! Reason: %s", pName, reason);
        SendClientMessageToAll(0xA10000AA,string);
        format(string, sizeof(string), "You have been kicked! Reason: %s", reason);
        SendClientMessage(targetid,0xA10000AA,string);
        Kick(targetid);
   }
   return 1;
}



Re: Help me here - maramizo - 18.03.2011

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Why not? Obviously he doesn't know what the error means, so instead of providing him with a quick fix, why not explain to him what the error means, and then he can fix it himself and learn something new? Then he won't have to rely on other people to solve it for him in the future if it happens again.
Looking at his logical level of English, I rather think he would skip your post when he sees the bulk of text, don't you agree?