AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is there a difference? (https://forums.alliedmods.net/showthread.php?t=134358)

GXLZPGX 08-03-2010 18:06

Is there a difference?
 
Is there a difference between:

PHP Code:

return PLUGIN_CONTINUE

and

PHP Code:

continue; 


Seta00 08-03-2010 18:27

Re: Is there a difference?
 
continue is used in loops, it means start the next iteration of the closest loop.
Example:
Code:
for (new i = 0; i < 10; ++i) {     for (new j = 0; j < 10; ++j) {         if (j == i) continue;         server_print("j != i"); // this code won't be executed when j == i     } }
return PLUGIN_CONTINUE means you're returning the value of PLUGIN_CONTINUE, which is defined on amxmodx.inc
The function provider will check your return value and act based on it. For instance, in most cases if you return PLUGIN_HANDLED it will block the default action.

joropito 08-03-2010 18:27

Re: Is there a difference?
 
As Seta said, there's difference :) (same post time :P)

GXLZPGX 08-03-2010 18:30

Re: Is there a difference?
 
Alright thanks. Now I never understood the loops. So basically, when using loops such as:

PHP Code:

new iPlayers[32];
new 
iNum;
get_playersiPlayersiNum"a" )

for( new 
0iNumi++ ) 

It will continue to add to "i" until it reaches iNum, then it will stop?

Seta00 08-03-2010 18:33

Re: Is there a difference?
 
No, you must put a code block inside the loop. In Pawn, an empty code block is {}
Code:
new iPlayers[32]; new iNum; get_players( iPlayers, iNum, "a" ) for( new i = 0; i < iNum; i++ ){}

GXLZPGX 08-03-2010 18:38

Re: Is there a difference?
 
Quote:

Originally Posted by Seta00 (Post 1260827)
No, you must put a code block inside the loop. In Pawn, an empty code block is {}
Code:
new iPlayers[32]; new iNum; get_players( iPlayers, iNum, "a" ) for( new i = 0; i < iNum; i++ ){}

Of course :) I just didn't feel I should put the rest in.

wrecked_ 08-03-2010 19:50

Re: Is there a difference?
 
continue:
Code:
// this loop will skip over the iteration if x is equal to 6 for( new x = 1; x < 9; x++ ) {     if( x == 6 )         continue;             // code         // x will never equal 6 in this loop, since we skip over it at the beginning }

return PLUGIN_HANDLED:
Code:
/* this loop will end the function and return 1 (PLUGIN_HANDLED)    when x is equal to 6 */     for( new x = 1; x < 9; x++ ) {     if( x == 6 )         return PLUGIN_HANDLED;             // code         // x will never equal anything above 5 in this loop     // which is kind of unnecessary, since you can just change the condition to x < 6 }


All times are GMT -4. The time now is 00:09.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.