Raised This Month: $ Target: $400
 0% 

return's .. need some explanations


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheWho
AlliedModders Donor
Join Date: Jul 2012
Old 03-11-2013 , 14:42   return's .. need some explanations
Reply With Quote #1

Hey,

Ok iam wondering if some peaple use
PHP Code:
return; 
or
PHP Code:
continue; 
in there plugins.

This is my way I think about that:
"return;" is the same as "return Plugin_Continue;"
and
"continue;" ist the same as "reruten Plugin_Handled;"
and NO I had written this correctly that way I think.

Now what is the right way?
I ask this because I always use "return Plugin_Handled;", "return Plugin_Continue;" and "return Plugin_Changed;"
And when that way I think is the right way what is then "return Plugin_Changed;" in the short form?

Last edited by TheWho; 03-11-2013 at 14:46.
TheWho is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 03-11-2013 , 14:45   Re: return's .. need some explanations
Reply With Quote #2

return and continue is used in loops, so in other cases you should use return Plugin_Handled/Continue/Stop/Whatever
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
TheWho
AlliedModders Donor
Join Date: Jul 2012
Old 03-11-2013 , 14:48   Re: return's .. need some explanations
Reply With Quote #3

You mean timers right?

But now when I use return in a timer, it will stop the timer? or will it begin from the first line of the timer?

Last edited by TheWho; 03-11-2013 at 14:50.
TheWho is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 03-11-2013 , 14:50   Re: return's .. need some explanations
Reply With Quote #4

Nope, I mean loops
Code:
for (new client = 1; client <= MaxClients; client++) {     // Make sure all players is in game     if (IsClientInGame(client))     {         // Ignore admins from being switched if immunity is enabled         if (GetConVar[SwitchTeamsImmunity][Value] && GetUserAdmin(client) != INVALID_ADMIN_ID) continue;         if (GetClientTeam(client) == DODTeam_Allies) // is player on allies?         {             // Yep, get the other team             ChangeClientTeam(client, DODTeam_Spectator);             ChangeClientTeam(client, DODTeam_Axis);             ShowVGUIPanel(client, "class_ger", INVALID_HANDLE, false);         }         else if (GetClientTeam(client) == DODTeam_Axis) // Nope.avi         {             // Needed to spectate players to switching teams without deaths (DoD:S bug: you dont die when you join spectators)             ChangeClientTeam(client, DODTeam_Spectator);             ChangeClientTeam(client, DODTeam_Allies);             ShowVGUIPanel(client, "class_us", INVALID_HANDLE, false);         }     } }
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
TheWho
AlliedModders Donor
Join Date: Jul 2012
Old 03-11-2013 , 14:53   Re: return's .. need some explanations
Reply With Quote #5

So continue is a loop stop?
But if I use continue in a non-loop it will not be stoped right?

Last edited by TheWho; 03-11-2013 at 15:02.
TheWho is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 03-11-2013 , 16:22   Re: return's .. need some explanations
Reply With Quote #6

Quote:
Originally Posted by TheWho View Post
So continue is a loop stop?
But if I use continue in a non-loop it will not be stoped right?
Continue does not stop the loop.
ajr1234 is offline
TheWho
AlliedModders Donor
Join Date: Jul 2012
Old 03-11-2013 , 17:40   Re: return's .. need some explanations
Reply With Quote #7

And Continue does not continue the loop?
TheWho is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 03-11-2013 , 17:50   Re: return's .. need some explanations
Reply With Quote #8

Quote:
Originally Posted by TheWho View Post
And Continue does not continue the loop?
PHP Code:
for (new 010i++)
{
     
blah blah
     blah

     
continue; // note this.

     
lololol
     lolol

The first part of the for loop will get executed, but the bottom part will not. The loop continues (i.e. starts execution back at the top after incrementing i) and repeats until i becomes >= 10. What you are confusing continue with is break.

PHP Code:
for (new 010i++)
{
     
blah blah
     blah

     
break; // note this.

     
lololol
     lolol

break will exit the loop.
ajr1234 is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 03-11-2013 , 17:58   Re: return's .. need some explanations
Reply With Quote #9

A very simplistic way of thinking about it is:

- continue will start the loop from the beginning, carrying out the loop operation (e.g. i++)
- break will exit the loop
- return will exit the function itself (and consequently any loop)
ajr1234 is offline
TheWho
AlliedModders Donor
Join Date: Jul 2012
Old 03-12-2013 , 16:26   Re: return's .. need some explanations
Reply With Quote #10

Thanks verry much guys!
You helped me a lot that was really confusing
TheWho is offline
Reply



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

Forum Jump


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


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