Raised This Month: $ Target: $400
 0% 

Function callbacks with enum structs?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 02-04-2019 , 03:49   Function callbacks with enum structs?
Reply With Quote #1

I am trying to setup an enum struct to contain cvar handles, variables, and function callbacks for when they are changed, but the compiler is telling me there is a prototype mismatch. I imagine this is similar to the limitations with array members being unable to pass their sizes, so I suppose I shouldn't have expected this work in the first place...

PHP Code:
enum struct PluginData
{
    
Handle c_enable;
    
int enable;
    
    
void EnableChange(Handle convar, const char[] oldValue, const char[] newValue)
    {
        
this.enable StringToInt(newValue);
    }
};
PluginData cVars;
public 
void OnPluginStart()
{
    
cVars.c_enable CreateConVar("sm_enable""1.0""Enable plugin"0true0.0true1.0);
    
HookConVarChange(cVars.c_enable,cVars.EnableChange); //line 22

Code:
test.sp(22) : error 100: function prototypes do not match
NIGathan is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-04-2019 , 09:32   Re: Function callbacks with enum structs?
Reply With Quote #2

It's because methods on methodmaps and enum structs have a hidden fourth argument representing the methodmap/struct itself.

So, your EnableChange method's signature is actually this:

Code:
void EnableChange(PluginData this, Handle convar, const char[] oldValue, const char[] newValue)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 02-04-2019 at 09:34.
Powerlord is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 02-04-2019 , 18:53   Re: Function callbacks with enum structs?
Reply With Quote #3

Ah, that makes sense, I should have thought about that.. Thanks
NIGathan 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 15:34.


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