Poll: Change the API?
You do not have permission to vote in this poll.
Yes, break all the plugins
85.71%
6 85.71%
No, keep it as is
14.29%
1 14.29%
Total 7 vote(s) 100%
* You voted for this item. [Show Results]

API change in hook-adding
#11
Sounds good. Core is all done Smile
Reply
Thanks given by:
#12
I don't like polluting the global namespace so much. The hooks are used so rarely that it's not worth the few saved keystrokes.

What is more intriguing is (yet another) function signature:
cPluginManager.AddHook(HOOK_TYPE);  -- CallbackFunction is assumed to be named the same as in the old API
I'm still not sure, it'd make coding easier, but it's not good for maintenance, the line doesn't say anything about the function that will be called, it'd be confusing to the beginners.
Reply
Thanks given by:
#13
For some reason I can't add hooks. I get these errors:
Code:
[12:29:30] Plugin WorldEdit wants to add a hook (19), but it doesn't provide the callback function "OnPlayerBreakingBlock" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(13): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (27), but it doesn't provide the callback function "OnPlayerRightClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(14): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (27), but it doesn't provide the callback function "OnPlayerRightClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(16): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (27), but it doesn't provide the callback function "OnPlayerRightClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(17): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (23), but it doesn't provide the callback function "OnPlayerLeftClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(19): ?
[12:29:30] Stack trace end
[12:29:30] Plugin WorldEdit wants to add a hook (23), but it doesn't provide the callback function "OnPlayerLeftClick" for it. The plugin need not work properly.
[12:29:30] Stack trace:
[12:29:30]   [C](-1): AddHook
[12:29:30]   Plugins/WorldEdit/main.lua(20): ?
[12:29:30] Stack trace end
with this code:
	
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_BREAKING_BLOCK, SelectFirstPointHook); -- Add hook that gets called when selecting the first point.
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK,    SelectSecondPointHook);
	
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK,    RightClickCompassHook);
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK,    ToolsHook);
	
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK,     LeftClickCompassHook); -- Add hook OnPlayerLeftClick
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK,     SuperPickaxeHook);
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_JOINED,         OnPlayerJoined); -- Add hook OnPlayerJoined
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_ANIMATION,      OnPlayerAnimation); -- Add hook OnPlayerAnimation for left click compass
But it is fixed when I add
function OnPlayerBreakingBlock()
end
function OnPlayerRightClick()
end
function OnPlayerLeftClick()
end
Reply
Thanks given by:
#14
And those functions, SelectFirstPointHook etc, are they defined?
Reply
Thanks given by:
#15
Yes. They are in a different .lua file but they exist.
Reply
Thanks given by:
#16
Hmm, strange. Since the initialize function is called after everything has been loaded, the functions should be available as globals. They're not local, are they?
Reply
Thanks given by:
#17
The weird thing is that the server still searches for a function with the same name as before the API change
(HOOK_PLAYER_BREAKING_BLOCK and OnPlayerBreakingBlock)
but when the server calls the hook it calls the function I said it should use
(HOOK_PLAYER_BREAKING_BLOCK and SelectFirstPointHook)
Reply
Thanks given by:
#18
Oh, that might be the cause, the leftover code for hook function existence is based on the old API. I'll fix this later in the evening when I get home. I thought the old-named functions were called instead.
Reply
Thanks given by: NiLSPACE
#19
Or not. I tried calling AddHook(cPluginManager.HOOK_CHAT, HookChat) with a HookChat function defined, and everything worked fine.
Could you send your plugin to me?

I think I've fixed it. Try it now.
Reply
Thanks given by:
#20
You broke all plugins with that. Some of my plugins are not working, SignLock is not working, MCServer says it fix the call but plugins dont work.
Reply
Thanks given by:




Users browsing this thread: 3 Guest(s)