Page 1 of 1

Question: self.T_FOO fails for addon talents, is this okay?

Posted: Fri Oct 17, 2014 8:35 pm
by Nagyhal
Ever since I've started working with ToME, I've held the assumption that every talent in the game has its talent ID indexed by each and every actor. That is, if "FOO" is the short_name of a talent, then I can get the string "T_FOO" by looking up the "T_FOO" key (identical to the string value it returns) in the main table possessed by any actor.

Today, I learnt this is not true.

NPCs aren't indexing the talent IDs of talents added in the addons I've created, although the player character always starts with these values. They do index the talents in "talents_def" and similar tables - it's just the direct index to a talent ID that's lacking.

Because I've always accessed talent IDs this way, I've noticed that features which have worked for the player are breaking now I'm seeing NPCs try to use them.

I've looked through a number of different addons and have come to the conclusion that I'm not doing anything drastically wrong.

Passing the talent IDs directly wouldn't do me any harm, as there's no way any given function could tell the difference, but doing so would break stylistically with the code I've seen in ToME and I have the feeling things aren't supposed to be this way.

To give a direct example, I can open the Lua console and enter:

Code: Select all

=game.player.T_FLAME
    1 :=: T_FLAME  --beholder player character doesn't know flame, but has indexed the talent ID as it has all other talents
=game.player.T_FLAME_LASER
    1 :=: T_FLAME_LASER --fine
=uids[1247].name  --let's look at some random NPC
    1 :=: brown bear
=uids[1247].T_FLAME
    1 :=: T_FLAME  --bears don't cast flame, but init with the talent ID "T_FLAME" indexed anyway
=uids[1247].T_FLAME_LASER  --no output for my beholder addon talent id
When I first saw this, my instinct was to try to stick a band-aid on it.

Possessed by a fell mood, and eager to the be the first to uncover the causes of a mysterious bug, I spent most of the morning talking to my rubber duck as I waded through the Actor class's init process. While I had fun learning lots about the class system, I didn't come close to finding out why this is happening. So if it needs fixing, I'm certainly in no position to fix it.

On the other hand, maybe things are designed to work this way, and someone could explain why?

Re: Question: self.T_FOO fails for addon talents, is this ok

Posted: Sat Oct 18, 2014 8:47 am
by darkgod
Can you show me how&where you load the talents files please ?

Re: Question: self.T_FOO fails for addon talents, is this ok

Posted: Sat Oct 18, 2014 12:24 pm
by grayswandir
It's because something's doing require 'mod.class.NPC' at the top of a talent file somewhere. I tried sticking require 'mod.class.Player' at the top of a talent file and that didn't have all the talents, either.

Re: Question: self.T_FOO fails for addon talents, is this ok

Posted: Sat Oct 18, 2014 2:17 pm
by darkgod
Why do that ??

Re: Question: self.T_FOO fails for addon talents, is this ok

Posted: Tue Nov 11, 2014 8:08 pm
by Nagyhal
Sorry for not replying sooner, DarkGod.

I load all my talent files in the load.lua hooks file, like this:

Code: Select all

class:bindHook("ToME:load", function(self, data)
	ActorTalents:loadDefinition("/data-beholder-cont-beta/talents/spells.lua")
Then spells.lua has a list of things like:

Code: Select all

load("/data-beholder-cont-beta/talents/lightningeye.lua")
So, as far as I know there's nothing out of the ordinary going on here!

Re: Question: self.T_FOO fails for addon talents, is this ok

Posted: Tue Nov 11, 2014 8:33 pm
by Nagyhal
grayswandir wrote:It's because something's doing require 'mod.class.NPC' at the top of a talent file somewhere. I tried sticking require 'mod.class.Player' at the top of a talent file and that didn't have all the talents, either.
Ah, okay. I removed all instances of that and it was fixed. All talent IDs load for all actors, just as desired!
darkgod wrote:Why do that ??
The codebase I inherited did that and so far nothing had visibly broken, so it seemed natural to carry on that way.

Actually, talent files in the main ToME code do it all the time. Addon code being unable to do the same is extremely perplexing!

Thanks for your help anyway, guys! :D