Page 1 of 1

Champion:trainSkill Component Bug on Party Creation

Posted: Sun Mar 15, 2015 8:40 am
by David Ward
Hi guys. I'm trying to figure out how NOT to make the Champion:trainSkill(name, times) component fill up a skill with all 5 skill points, even if "times" is only set to 1, on the party creation screen.

This is the code I have right now for a class that should start with 1 on "armors" skill, and 1 on "shields" skill:

Code: Select all

defineTrait{
	name = "knight",
	uiName = "Knight",
	icon = 97,
	description = "As a knight you believe that good preparation is the key to triumph in combat. You are specialized in wielding armor and using the shield.",
	gameEffect = [[
	- Health 60 (+10 per level), Energy 30 (+3 per level)
	- Weight of equipped armor is reduced by 50%.
	- Add +1 to both your Armor and Shields skills at start.]],
	onRecomputeStats = function(champion, level)
		if level > 0 then
			level = champion:getLevel()
			champion:addStatModifier("max_health", 60 + (level-1) * 10)
			champion:addStatModifier("max_energy", 30 + (level-1) * 3)
			champion:trainSkill("armors",1)
			champion:trainSkill("shields",1)
		end
	end,
}
For some reason, as soon as I choose the "knight" class, it shoots those two skills up to 5 points. Not sure why, or how to fix it. Any help would be much appreciated, thank you.

Re: Champion:trainSkill Component Bug on Party Creation

Posted: Sun Mar 15, 2015 8:57 am
by minmay
onRecomputeStats is called every frame (or something close to every frame). So your code is increasing those skills by 1 every frame. It is completely inappropriate to put that sort of thing in an onRecomputeStats hook.
Instead, when the game actually starts, you should check for that trait and train those skills if the champion has it.

Re: Champion:trainSkill Component Bug on Party Creation

Posted: Sun Mar 15, 2015 5:41 pm
by David Ward
I see. Still learning this! Thank you.
Instead, when the game actually starts, you should check for that trait and train those skills if the champion has it.
We're trying to make it so that a particular class gets its skills added automatically (like "armors" and "shields" for the knight), plus give the player the option to add 2 more skill points. Still working on that.

Is there also a way to set a skill level for a skill to 0? Or at least reduce a skill level?

For example:

Code: Select all

			champion:trainSkill("lgt_weapons", -1)
Would that work when called, reducing the lgt_weapons skill by 1?

Re: Champion:trainSkill Component Bug on Party Creation

Posted: Sun Mar 15, 2015 11:39 pm
by Azel
This should cover your needs, I think:
viewtopic.php?f=22&t=9024

Re: Champion:trainSkill Component Bug on Party Creation

Posted: Mon Mar 16, 2015 1:31 am
by David Ward
Looks awesome, Azel. Checking into it now. Thanks for the reference.