Raised This Month: $ Target: $400
 0% 

Questions about functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fr33m@n
Veteran Member
Join Date: May 2008
Location: France Marne
Old 03-11-2017 , 06:07   Questions about functions
Reply With Quote #1

1) I'm always a robot when it come to function registering.
I always set them with public tag when needed and avoid to use it when not needed.
But what do public tag exactly ?

2) Question about usage of a custom function with inside a return PLUGIN_* value in forward or event hook. Does the function trigger the same return in the forward/event hook. Same question if the function is marked as public.

3) I saw recent usage of an @ instead of using public.
IE :
register_clcmd("test", "@cmd_test")
@cmd_test(id)

I have no idea of when to use this.
Fr33m@n is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-11-2017 , 06:42   Re: Questions about functions
Reply With Quote #2

1) Unless the function is callback or forward, you don't need "public". You use it when you need the function be accessed from outside your plugin scope.

2) Not sure to understand. In a custom function, you return whatever you want.

3) "@function() {}" is the same as "public function() {}". It can be handy if you do some macro with it but usually, I like you use it to differentiate callback from forward (just a visual hint).
__________________
Arkshine is offline
Fr33m@n
Veteran Member
Join Date: May 2008
Location: France Marne
Old 03-11-2017 , 07:04   Re: Questions about functions
Reply With Quote #3

Thanks for your response.

About question 2 :
IE :



PHP Code:
public plugin_init()
{
    
// . . .
    
register_clcmd("awp""cmd_awp")
    
// . . .
}

// return PLUGIN_HANDLED can be used to block the command

public cmd_awp()
{
    
my_custom_function()
    return 
PLUGIN_CONTINUE
}

my_custom_function() // or public my_custom_function()
{
    return 
PLUGIN_HANDLED

Does my_cunstom_function() return affect cmd_awp() return value ?
Fr33m@n is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-11-2017 , 07:18   Re: Questions about functions
Reply With Quote #4

Unless you check my_custom_function() for a specific returned value in cmd_awp(), no. If you want to affect cmd_awp(), you would need to use "return my_custom_function()".
__________________

Last edited by Arkshine; 03-11-2017 at 07:19.
Arkshine 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:56.


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