Raised This Month: $ Target: $400
 0% 

question about functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-22-2010 , 20:15   question about functions
Reply With Quote #1

I have a question about calling a function from another function.
I don't know how i can explain it well, so i'll make an example.


Code:
public client_connect(id)
{
    check_something(id) // This is called. 
    
    client_print(id, print_chat, "some stuff");
}

public check_something(id)
{
    // do some stuff here.
}
My question is the order the code works in:
is it like:

- client connects
- client_connect is called
- client_connect calls check_something and waits
- check_something does something
- client_connect prints the msg

or like this:

- client connects
- client_connect is called
- client_connect calls check_something and prints the message
- check_something does something

This may be a stupid question, but i need the answer for a plugin i'm making.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-22-2010 , 20:18   Re: question about functions
Reply With Quote #2

The first scenario is correct.

check_something() is called and completed before client_print() will be called. Meaning everything in check_something() is executed before client_print().
__________________
fysiks is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-22-2010 , 20:20   Re: question about functions
Reply With Quote #3

Thanks, that's all i needed.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-22-2010 , 20:21   Re: question about functions
Reply With Quote #4

Quote:
Originally Posted by drekes View Post
- client connects
- client_connect is called
- client_connect calls check_something and waits
- check_something does something
- client_connect prints the msg
Sorry for not responding on Steam. I was AFK.

EDIT: Oh, hi fysiks.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-22-2010 , 20:22   Re: question about functions
Reply With Quote #5

Quote:
Originally Posted by wrecked_ View Post
Sorry for not responding on Steam. I was AFK.
No problem, this may be usefull to other people to i think.

EDIT: Let's say i return PLUGIN_HANDLED in public checksomething(id). Will client_connect still continue then? and if so, is there a way to stop that?
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.

Last edited by drekes; 06-22-2010 at 20:30.
drekes is offline
Send a message via MSN to drekes
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-22-2010 , 20:38   Re: question about functions
Reply With Quote #6

Quote:
Originally Posted by drekes View Post
No problem, this may be usefull to other people to i think.

EDIT: Let's say i return PLUGIN_HANDLED in public checksomething(id). Will client_connect still continue then? and if so, is there a way to stop that?
Yes, it'll still continue.

To stop that, you could do something like this.

Code:
func() {     if( check_something() == PLUGIN_HANDLED )     {         return PLUGIN_HANDLED;     }     // stuff }
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-22-2010 , 20:39   Re: question about functions
Reply With Quote #7

awesome, Thanks guys
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-22-2010 , 20:40   Re: question about functions
Reply With Quote #8

Quote:
Originally Posted by drekes View Post
awesome, Thanks guys
No problem.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-22-2010 , 21:50   Re: question about functions
Reply With Quote #9

if i have a while loop that i break in check_something(id), can i do something like this?
Code:
if(check_something(id) == break)
    return PLUGIN_HANDLED;
EDIT: I tried it, can't compile. How do i do this then? I can't return PLUGIN_HANDLED after break to.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.

Last edited by drekes; 06-22-2010 at 21:52.
drekes is offline
Send a message via MSN to drekes
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-22-2010 , 22:34   Re: question about functions
Reply With Quote #10

Code:
func() {     new blah     check_something(id, blah)     if( blah == 1 )         // break occured in check_something()         // ... } check_something( id, &val ) {     while()     {         if()         {             val = 1                 break;         }     } }
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ 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 17:10.


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