SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/07/2015, 10:14 PM   #11
Nin9r
Huge Clucker
 
Join Date: Feb 2015
Posts: 331
Reputation: 3
Default Re: AW: How to use return 1/0 ?

Quote:
Originally Posted by Mencent View Post
1.) It is better, otherwise the codes continue also if you don't want it.

2.) No, it is not a problem but the codes will continue also if you don't want it.
So, which is good?

Code:
if(PlayerData[playerid][pLoaded] == 1)
	    	{
				SetPlayerCheckpoint(playerid, 997.4530, -920.2242, 42.1797, 10.0);
			}
	    	else if(PlayerData[playerid][pLoaded] == 2)
	    	{
				SetPlayerCheckpoint(playerid, 935.0326, -1724.0830, 13.5469, 10.0);

	    	}
or
Code:
if(PlayerData[playerid][pLoaded] == 1)
	    	{
				SetPlayerCheckpoint(playerid, 997.4530, -920.2242, 42.1797, 10.0);
return 1;
			}
	    	else if(PlayerData[playerid][pLoaded] == 2)
	    	{
				SetPlayerCheckpoint(playerid, 935.0326, -1724.0830, 13.5469, 10.0);
return 1;
	    	}
Nin9r is offline   Reply With Quote
Old 27/07/2015, 10:19 PM   #12
!damo!spiderman
Huge Clucker
 
!damo!spiderman's Avatar
 
Join Date: Oct 2006
Posts: 244
Reputation: 160
Default Re: AW: How to use return 1/0 ?

Quote:
Originally Posted by Nin9r View Post
So, which is good?

Code:
if(PlayerData[playerid][pLoaded] == 1)
	    	{
				SetPlayerCheckpoint(playerid, 997.4530, -920.2242, 42.1797, 10.0);
			}
	    	else if(PlayerData[playerid][pLoaded] == 2)
	    	{
				SetPlayerCheckpoint(playerid, 935.0326, -1724.0830, 13.5469, 10.0);

	    	}
or
Code:
if(PlayerData[playerid][pLoaded] == 1)
	    	{
				SetPlayerCheckpoint(playerid, 997.4530, -920.2242, 42.1797, 10.0);
return 1;
			}
	    	else if(PlayerData[playerid][pLoaded] == 2)
	    	{
				SetPlayerCheckpoint(playerid, 935.0326, -1724.0830, 13.5469, 10.0);
return 1;
	    	}
Really depends on what you want to do. Returning will exit the function. So if you want to cancel execution of other things when a condition is met then returning can be good. We can't really tell you what is best in your example code as we don't know the function the code is enclosed in, however another way to write it would be like this

PHP Code:
if(PlayerData[playerid][pLoaded] == 1)
{
    
SetPlayerCheckpoint(playerid997.4530, -920.224242.179710.0);
    return 
1;
}       
SetPlayerCheckpoint(playerid935.0326, -1724.083013.546910.0); // This won't be called if PlayerData[playerid][pLoaded] == 1 as we have exited the function with return; 
__________________
!damo!spiderman is offline   Reply With Quote
Old 27/07/2015, 11:34 PM   #13
Crayder
Banned
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,329
Reputation: 652
Default Re: How to use return 1/0 ?

You should probably go look in the Pawn Language Guide.

"The return statement ends a function and sets the result of the function. It need not appear at the very end of the function; early exits are permitted." (Page 9)

There is a lot more information on it, that's just one.
Crayder is offline   Reply With Quote
Old 27/07/2015, 11:44 PM   #14
SpikeSpigel
Huge Clucker
 
Join Date: Jul 2014
Posts: 270
Reputation: 10
Default Re: How to use return 1/0 ?

return 1 - true
return 0 - false.

In the most cases you need to use return 1, you will get with time when to use return 1 or return 0.

The simpliest explication .

return 1 - true - Return the function.
return 0 - false - Doesn't return the function.
__________________
+REP if I helped you :P
SpikeSpigel is offline   Reply With Quote
Old 28/07/2015, 12:19 AM   #15
!damo!spiderman
Huge Clucker
 
!damo!spiderman's Avatar
 
Join Date: Oct 2006
Posts: 244
Reputation: 160
Default Re: How to use return 1/0 ?

Quote:
Originally Posted by SpikeSpigel View Post
return 1 - true
return 0 - false.

In the most cases you need to use return 1, you will get with time when to use return 1 or return 0.

The simpliest explication .

return 1 - true - Return the function.
return 0 - false - Doesn't return the function.
The simplest and wrong explanation is the one above. Using the return statement will always return the function, no matter what you return
__________________
!damo!spiderman is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the diffrences between Return True and Return False davidstyle1125 Scripting Help 4 09/12/2014 08:34 PM
return true vs return 1 +rep genesis87 Scripting Help 3 02/02/2012 08:24 AM
When do I return? NiiRV4N4 Help Archive 9 13/06/2010 04:14 PM


All times are GMT. The time now is 01:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.