Raised This Month: $51 Target: $400
 12% 

Return type of a new GlobalForward


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
usernameisrequired
New Member
Join Date: Dec 2021
Old 12-12-2021 , 05:42   Return type of a new GlobalForward
Reply With Quote #1

Hi,

I'd like to create a declaration for "listening" to a new GlobalForward, with a prototype return type of void.

The wiki page for Global Forwards has an example of creating a new forward with the prototype:

Code:
forward void OnClientDied(int attacker, int victim, const char[] weapon, bool headshot)
with the implementation:

Code:
new GlobalForward("OnClientDied", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell);
However, the ExecType parameter ET_Event would seem to imply a prototype with the return type of Action:

Quote:
ET_Event

Acts as an event with the Actions defined in core.inc, no mid-Stops allowed, returns highest
These pieces of information seem to be in conflict. For creating a prototype that returns void, shouldn't one instead create the new GlobalForward with the ExecType of ET_Ignore? Is the wiki incorrect here, or am I misunderstanding something about how GlobalForwards work? Can I safely declare a prototype that returns void despite ET_Event expecting to return Action?

I'm mainly asking this because I'd like to "subscribe" to a GlobalForward created by another plugin author using this exact pattern (probably copied from this wiki example snippet), and I'm unsure if I can just declare the forward prototype in my own code as public void, or do I have to use a public Action that returns Plugin_Continue because the GlobalForward's ExecType is ET_Event? I just want my plugin to have read access to the forward's parameters, not to block the call or modify the pushed values. It seems that the Plugin_Continue enum value is currently defined as 0, so perhaps returning void would result in the same behaviour, but I'm wondering if this kind of use would be well-defined.

Last edited by usernameisrequired; 12-12-2021 at 06:42.
usernameisrequired is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 12-12-2021 , 06:47   Re: Return type of a new GlobalForward
Reply With Quote #2

You can use ET_Ignore without any worry. That's what I have always practiced when it comes to global/private forwards expecting void return values.
cravenge is offline
usernameisrequired
New Member
Join Date: Dec 2021
Old 12-12-2021 , 07:03   Re: Return type of a new GlobalForward
Reply With Quote #3

Quote:
Originally Posted by cravenge View Post
You can use ET_Ignore without any worry. That's what I have always practiced when it comes to global/private forwards expecting void return values.
Sorry, perhaps my rambling message was a bit unclear. I meant that there is another plugin whose code I don't have control over, where they are using ET_Event for what is supposedly a void forward. Since this is not a plugin I write, I can't change the ExecType. I'd like to use their global forward as:

Code:
public void ThirdPartyStuffHappened(int third_party_data)
{
    DoMyThing(third_party_data);
}
but am wondering if I should instead be doing the more wordy

Code:
public Action ThirdPartyStuffHappened(int third_party_data)
{
    DoMyThing(third_party_data);
    return Plugin_Continue;
}
despite the AlliedMods wiki example linked in the OP post seemingly suggesting otherwise.
usernameisrequired is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-06-2022 , 06:42   Re: Return type of a new GlobalForward
Reply With Quote #4

void is an implicit 0 return, so is equivalent to retuning Plugin_Continue for ET_Event. I've updated the wiki page to use ET_Ignore, which is more correct for the implementation in the example.
__________________
asherkin 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 07:17.


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