SA-MP Forums Archive
Return Values Help - 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: Return Values Help (/showthread.php?tid=654424)



Return Values Help - TadePoleMG - 28.05.2018

Hi

There is a php code and i wanted to know that can i add return 0 or not or whatever to do.

GOOD?
PHP код:
//==============================================================================
// Math Quiz Answer
//==============================================================================
    
if(strval(text) == MathQuizTest && MathQuizTest != -1)
    {
    
CorrectAnswer(playerid);
    return 
0;
    } 
Or This is GOOD?
PHP код:
//==============================================================================
// Math Quiz Answer
//==============================================================================
    
if(strval(text) == MathQuizTest && MathQuizTest != -1)
    {
    
CorrectAnswer(playerid);
    } 
Or This is GOOD?
PHP код:
//==============================================================================
// Math Quiz Answer
//==============================================================================
    
if(strval(text) == MathQuizTest && MathQuizTest != -1CorrectAnswer(playerid); 
Suggest guys which right otherwise tell me how to make right.

Thank You


Re: Return Values Help - GTLS - 28.05.2018

return 0 stands for return false
return 1 stands for return true

You should return 1 or return true at the place where you want a function to be called correctly. At each Command or function's true part, you should return 1 and visa versa.

PHP код:
if(strval(text) == MathQuizTest && MathQuizTest != -1
    { 
        
CorrectAnswer(playerid); 
        return 
1
    }  
 else return 
0
or

PHP код:
if(strval(text) == MathQuizTest && MathQuizTest != -1) return  CorrectAnswer(playerid); 
 
 else return 
0



Re: Return Values Help - TadePoleMG - 28.05.2018

This is under OnPlayerText So Is there a effect of return 1 on other statements?


Re: Return Values Help - TadePoleMG - 28.05.2018

This code
PHP код:
if(strval(text) == MathQuizTest && MathQuizTest != -1
    { 
        
CorrectAnswer(playerid); 
        return 
1
    }  
 else return 
0
show Warning 225: unreachable code

Help me Guys pls


Re: Return Values Help - GTLS - 29.05.2018

Dont add else return 0. You are already returning something at the end of the callback.


Re: Return Values Help - Banana_Ghost - 29.05.2018

Quote:
Originally Posted by TadePoleMG
Посмотреть сообщение
This is under OnPlayerText So Is there a effect of return 1 on other statements?
When you return 1 under OnPlayerText, it allows the text to be sent to the chat. If you return 0, you can use the text and then not send it to the chat.