Page 1 of 1

Need coding help: on_learn

Posted: Thu Feb 21, 2013 1:00 pm
by Parcae2
So, in my Superload, I have added the following to the kinetic shield talent:

on_learn = function (self, t)
self:learnTalent(T_SPIKE_ALL_SHIELDS, true, 1)
end

But it errors out with the message '}' expected (to close '{' at line 4) near 'sustain_psi', where the start bracket is the one that begins the kinetic shield talent, and the missing end bracket is immediately after the stuff I added. What's gone wrong?

Re: Need coding help: on_learn

Posted: Thu Feb 21, 2013 5:00 pm
by Hachem_Muche
Talents are handled in a special way. The talent definition files are loaded and then reinterpreted into tables that the game uses.

The simplest way to add to an existing talent defnition is probably with a hook.

Something like

Code: Select all

class:bindHook("ToME:load", function(self, data)
	engine.interface.ActorTalents.talents_def.T_KINETIC_SHIELD.on_learn = <your function definition>
end)
If you need to modify a large number of talents, see http://forums.te4.org/viewtopic.php?f=36&t=35006

Re: Need coding help: on_learn

Posted: Thu Feb 21, 2013 5:40 pm
by Parcae2
Now my hooks file errors out with "unexpected symbol near )" in the final line.

Code: Select all

local class = require"engine.class"
local ActorTalents = require "engine.interface.ActorTalents"


class:bindHook("ToME:load", function(self, data)
	ActorTalents:loadDefinition("/data-mindslayer-simplicity/talents/psionic.lua")
   ActorTalents.talents_def.T_KINETIC_SHIELD.on_learn = function (self, t)
	self:learnTalent(T_SPIKE_ALL_SHIELDS, true, 1)
end)

Re: Need coding help: on_learn

Posted: Fri Feb 22, 2013 1:22 am
by lukep
It looks like you are only ending one of the functions, and not the other. Add another "end" between the two last lines.