Page 1 of 1

To Hook or to Superload?

Posted: Fri Feb 15, 2013 9:47 pm
by nate
Trying to set up a template for adding new talents on birth, so that I can play around with stuff. Have got this working with superloading, of which I'm proud (and grateful for help from this forum). I imagine that I could be doing the same thing with hooks instead. Would that be preferable? If so, I might need a little bit of help with it :)

Here's my superloaded code in mod/class/player.lua

Code: Select all

local _M = loadPrevious(...)

local base_onBirth = _M.onBirth

function _M:onBirth(birther)
   if not game.player:knowTalent(T_NEW_TALENT) then
		game.logSeen(self, "Player does not know new talent, adding.")
		game.player:learnTalent(game.player.T_NEW_TALENT, true, 1, {no_unlearn=true})
   else
   		game.logSeen(self, "Player already knows new talent.")
   end
    return base_onBirth(self, birther)
end

return _M
Like I was saying, this works fine. It's just that I imagine I could hook it onto onBirth instead. Would that be preferable? Why or why not? Can I hook off of any function, or only special, hookable functions?

Re: To Hook or to Superload?

Posted: Sat Feb 16, 2013 1:09 am
by HousePet
You can only hook onto special hook locations.

Hook > Superload > Superoverload > Overload

Re: To Hook or to Superload?

Posted: Sat Feb 16, 2013 1:50 am
by nate
And those hookable functions are those that are listed on the wiki page, and no other?

Why is hooking superior to superloading?

Re: To Hook or to Superload?

Posted: Sat Feb 16, 2013 9:34 pm
by Hachem_Muche
nate wrote:And those hookable functions are those that are listed on the wiki page, and no other?

Why is hooking superior to superloading?
There a few more hooks that have been added recently. Check out http://git.develz.org/?p=tome.git&a=sea ... mit&s=hook

Using hooks is better than superloading for the simple fact that you don't have to change any of the existing game code for your addon. Overloading and, to a lesser extent, superloading, replace parts of the game code with yours, often including many lines that you don't actually want to change. As the game develops in the future, and those parts change, your code needs to be updated accordingly or else it may introduce bugs and disable new features. In addition, different addons that overload or superload the same code are usually not compatible.

Re: To Hook or to Superload?

Posted: Sun Feb 17, 2013 1:21 am
by nate
Thanks! Now I have another skill to learn... :)