To Hook or to Superload?

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
nate
Wyrmic
Posts: 261
Joined: Fri Jan 18, 2013 8:35 am

To Hook or to Superload?

#1 Post 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?
Proud father of Fx4fx and Chronometer add-ons; proud mother of Fated add-on

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: To Hook or to Superload?

#2 Post by HousePet »

You can only hook onto special hook locations.

Hook > Superload > Superoverload > Overload
My feedback meter decays into coding. Give me feedback and I make mods.

nate
Wyrmic
Posts: 261
Joined: Fri Jan 18, 2013 8:35 am

Re: To Hook or to Superload?

#3 Post by nate »

And those hookable functions are those that are listed on the wiki page, and no other?

Why is hooking superior to superloading?
Proud father of Fx4fx and Chronometer add-ons; proud mother of Fated add-on

Hachem_Muche
Uruivellas
Posts: 744
Joined: Thu Nov 18, 2010 6:42 pm

Re: To Hook or to Superload?

#4 Post 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.
Author of the Infinite 500 and PlenumTooltip addons, and the joys of Scaling in ToME.

nate
Wyrmic
Posts: 261
Joined: Fri Jan 18, 2013 8:35 am

Re: To Hook or to Superload?

#5 Post by nate »

Thanks! Now I have another skill to learn... :)
Proud father of Fx4fx and Chronometer add-ons; proud mother of Fated add-on

Post Reply