Quote:
Originally Posted by KliPPy
I may be wrong, but iirc I read that there was an update that made it so all functions are implicitly public and that's why you don't see a difference when you remove the keyword
Public functions won't throw "unused" warnings and also any parameters you don't use in the function body won't throw the warning either. Just make any function you provide to another function (creating callbacks) public.
|
Hi, thanks for your reply.
Take this script:
PHP Code:
#include <sourcemod>
public void OnPluginStart() {
RegAdminCmd("sm_public", sm_public, ADMFLAG_KICK, _, _, _);
}
// this function is passed as a callback to RegAdminCmd
Action sm_public(int client, int args) {
// args is not used, compiler does not complain
func('a');
RequestFrame(func2);
return Plugin_Handled;
}
// this function is not passed as a callback anywhere
void func(any data) {
// data is not used, compiler complains
}
// this function is passed as a callback to RequestFrame()
void func2(any data) {
// data is not used, compiler does not complain
}
The compiler only complains about the parameter 'data' not being used in the function 'func', as func is not used as a callback anywhere. Compare this to func2, which is passed as a callback to RequestFrame(). Even though the func2 definition does not use the parameter, the compiler does not complain. So, it seems in 1.9 the compiler knows if a function has been passed as a callback to another function somewhere, and makes it public (explains the unused parameter warning suppression). Therefore, I don't think its necessary to use public when defining callback functions anymore. Would there be any situation where this would have adverse effects, other than stylistic/readability reasons?
Thank you,
adma