Need coding help: on_learn

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
Parcae2
Uruivellas
Posts: 709
Joined: Sat Jan 14, 2012 12:02 am

Need coding help: on_learn

#1 Post 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?

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

Re: Need coding help: on_learn

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

Parcae2
Uruivellas
Posts: 709
Joined: Sat Jan 14, 2012 12:02 am

Re: Need coding help: on_learn

#3 Post 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)

lukep
Sher'Tul Godslayer
Posts: 1712
Joined: Mon Mar 14, 2011 10:32 am
Location: Canada

Re: Need coding help: on_learn

#4 Post 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.
Some of my tools for helping make talents:
Melee Talent Creator
Annotated Talent Code (incomplete)

Post Reply