[Tutorial] /cuff and /uncuff Tutorial (sscanf)+(ZCMD)
#4

Quote:
Originally Posted by Sreyas
View Post
Code:
else if(gTeam[playerid] == LSPD)
                          {
                                  SendClientMessage(playerid, 0xFF0000, "[ERROR]: you can't use this on a law enforcer!");
                                  return 1;
                          {
                          return 1;
Code:
 else if(!IsPlayerConnected(targetid))
           {
                   SendClientMessage(playerid, 0xFF0000, "[ERROR]: Invalid ID!");
                   return 1!
           }
fix that ^^ i didnt look much ahead and i wont raise hand to much use of else if s
While I usually don't complain about the excessive use of unnecessary else if statements, I do get annoyed by it. A lot of people find it reasonable to use them in a situation where the given condition can only be maximum two states and thus making an else if statement pointless and may even become "ineffective":
PHP Code:
if(IsPlayerConnected(playerid))
{
    
// Some code ...
}
else
{
    if(!
IsPlayerConnected(playerid))
    {
        
// Some other code ...
    
}

Given that, it seems like the OP has a bad habit of doing just that. I see the following reoccur more than a few times throughout the tutorial:
PHP Code:
if(IsPlayerConnected(playerid))
{
    
// Some code ...
    
return 1;
}
else if(!
IsPlayerConnected(playerid))
{
    
// Some other code ...
    
return 1;

A player is either connected or not. In this case, a simple else statement is the best way to go.

To drop the whole else statement altogether, the function would have to return a value in the if statement above that:
PHP Code:
if(condition)
{
    
// Some code...
    
return someValue;
}
// Code under this if statement is automatically the else statement, that is without explicitely using the else keyword.
return someOtherValue
Not explicitly using the else statement may reduce readability for programmers who are used to using it in such cases. I tend to not use it, but I'm fine with either.

Here's another mistake I came across:
Quote:
Originally Posted by Eoussama
View Post
PHP Code:
if(IsCuffed == true)
{
    return 
1;
}
else if(
IsCuffed == true)
{
    return 
1;

EDIT: Your boolean variable 'isCuffed' will only work when nobody is cuffed. Once 1 player on the server is cuffed, nobody else can get cuffed.
Reply


Messages In This Thread
/cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 01.10.2016, 14:58
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Kruno88 - 01.10.2016, 15:11
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by SyS - 01.10.2016, 15:14
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by AndySedeyn - 01.10.2016, 15:53
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 01.10.2016, 16:11
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 08.12.2016, 10:24
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Dayrion - 09.12.2016, 00:12
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by XxFiGhteRXx - 31.12.2016, 10:36
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Stinged - 31.12.2016, 10:51
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Triggerz - 22.01.2017, 18:57
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by RyderX - 22.01.2017, 19:29
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by PaRking - 22.01.2017, 19:35
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by RyderX - 22.01.2017, 19:36
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by PaRking - 22.01.2017, 19:38
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by RyderX - 22.01.2017, 19:39
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 22.01.2017, 19:40
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Triggerz - 22.01.2017, 19:43
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Triggerz - 22.01.2017, 19:45
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by RyderX - 22.01.2017, 19:49
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Eoussama - 22.01.2017, 19:50
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by Triggerz - 22.01.2017, 19:54
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by JohnFlores - 24.07.2017, 14:22
Re: /cuff and /uncuff Tutorial (sscanf)+(ZCMD) - by coool - 24.07.2017, 15:16

Forum Jump:


Users browsing this thread: 1 Guest(s)