nate wrote:Now I'm taking a look at talents and trying to figure out how to superload them. Talent files are collections of what look like tables labelled newTalent, but that can't be quite right, because wouldn't each of these tables overwrite the last? So what exactly are these?
Not exactly.
newTalent() is a T-Engine 4 function that takes a table describing a talent as its argument and makes it accessible to Actor objects. It uses a little more of Lua's syntactic sugar.
Code: Select all
-- Two ways to pass a single table as a function argument
myfunc{}
myfunc({})
The same thing exists for quotes, too.
Code: Select all
-- All identical
myfunc2""
myfunc2 ""
myfunc2("")
Just remember that it only works for single arguments. If you tried
you'd get an error. When in doubt, use parentheses.
nate wrote:And, from a superloading perspective, how do I go about accessing their individual functions and changing them? Do I have to figure out the talent id in some table of talents to access their individual .actions and .infos? It seems like this is perfectly possible, but wouldn't work along the same lines of the previous superloads. It also seems like there is probably more than one way to do it. (I've never used a powerful interpreted language like Lua before, it kind of scares me :) )
Superloading the
data/ subdirectory generally doesn't work. You can only superload T-Engine 4 classes, which are pretty much all in
mod/class/ and
mod/dialogs/. Modifying talents is
best done using hooks.
nate wrote:EDIT: Oh, and let me clarify something: even though I am modding player.lua, onEnterLevel is still a function belonging to class Actor, because the beginning of player.lua loads module (x, class.inherit(mod.class.Actor, etc)) ? Is that correct?
I'm afraid not. See? My
earlier mistake was confusing!
onEnterLevel() is in
Player.lua (line 115 in v1), not
Actor.lua. Your superloaded function replaces the old Player one.
If you were to replace one of Actor's functions in your superloaded Player, it still wouldn't change the one in Actor. Your replacement would only be used when called from a table referencing
mod.class.Player. Your version in Player would override the version from Actor only for Player objects.
class.inherit() makes the class you're defining a child class of each of its arguments. So Player is an Actor, Player implements the PlayerRest interface, Player implements the PlayerRun interface, and so on. It populates
_M (notice it's part of the
module() call) with all the functions, etc. of all its parent classes so that you can use it as if it was any of them. That is, you can use a Player object for any function that expects an Actor object (or a PlayerRest object, or...).
It creates what's called an
isa relationship. So Player
isa Actor, but Actor
is not a Player; they're not interchangeable. You can only use a Player as an Actor, not an Actor as a Player.
It's as close as Lua gets to
object-oriented multiple inheritance. Whole books have been written about
OOP, but it'll rarely be something that addon authors need to worry about unless adding pretty major functionality to a module.
To recap:
newTalent() is a function that uses a shorthand syntax; you should use hooks for talents; and ignore
class.inherit() as much as possible until you have a decent grasp of object-oriented inheritance because it's not likely to be immediately important.
I hope that all comes across as less confusing than I think it does.