View Single Post
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