AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   question about functions (https://forums.alliedmods.net/showthread.php?t=130339)

drekes 06-22-2010 20:15

question about functions
 
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.

fysiks 06-22-2010 20:18

Re: question about functions
 
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().

drekes 06-22-2010 20:20

Re: question about functions
 
Thanks, that's all i needed.

wrecked_ 06-22-2010 20:21

Re: question about functions
 
Quote:

Originally Posted by drekes (Post 1216712)
- 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.

drekes 06-22-2010 20:22

Re: question about functions
 
Quote:

Originally Posted by wrecked_ (Post 1216719)
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?

wrecked_ 06-22-2010 20:38

Re: question about functions
 
Quote:

Originally Posted by drekes (Post 1216723)
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 }

drekes 06-22-2010 20:39

Re: question about functions
 
awesome, Thanks guys

wrecked_ 06-22-2010 20:40

Re: question about functions
 
Quote:

Originally Posted by drekes (Post 1216731)
awesome, Thanks guys

No problem.

drekes 06-22-2010 21:50

Re: question about functions
 
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.

wrecked_ 06-22-2010 22:34

Re: question about functions
 
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;         }     } }


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

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