Page 1 of 1

Adding skill traits in correct game order

Posted: Sat Jul 18, 2020 5:42 am
by akroma222
Hey All,

Q - is there a way to track / mimic / replicate the correct ordering grimrock uses to add skill traits to a champion that have been added simultaneously

I have a custom traits menu and my system can correctly track and display traits as they are displayed without the custom menu
- except - when skill traits from more than 1 skill are added simultaneously

What results is my custom menu displaying some traits out of order - noticeable when hovering over them and getting an incorrect vanilla tooltip (mouse hovering over Reach trait and getting the air mastery tooltip)
SpoilerShow
Image
If the player adds more than one skill trait while in the skills menu but one at a time (spend points, accept, get 1 trait, spend more points, accept, get another trait) - this works fine

In my testing, I actually added all skill traits simultaneously, but spent the points in skills in both forward and reverse priority ordering, then accepted them all together. Neither test provided any useful insight into ordering....
I suspect the game may use a pairs function not ipairs - so correct tracking abovementioned would not be possible??

If not possible my options I can see are creating custom tooltips for the traits menu (which I hadnt intended but can script) - OR - asking the players nicely to avoid adding multiple skill traits simultaneously

Any ideas or suggestions??
Akroma :)

Re: Adding skill traits in correct game order

Posted: Sat Jul 18, 2020 5:56 am
by Isaac
I've never delved into this aspect before, so forgive possibly the naive question, but is there some reason not to update the table used by your menu on every frame? (so that it's always accurate)

Re: Adding skill traits in correct game order

Posted: Sat Jul 18, 2020 6:00 am
by minmay
Unfortunately, the order in which skills are trained when you click "Apply" on the skill screen is undefined. It can be different every time. Your guess of pairs was correct.

However, you can work around this particular problem by removing the traits yourself, then immediately re-adding them in an order that you do know.

Re: Adding skill traits in correct game order

Posted: Sat Jul 18, 2020 6:02 am
by Isaac
This would be updating the table, yes? ;) (...though not every frame).

Re: Adding skill traits in correct game order

Posted: Sat Jul 18, 2020 6:22 am
by akroma222
Thankyou both! :D
Impossible with pairs, thanks minmay for confirming that
So - ill add a simple function to remove and re-add the traits

Isaac, at the moment the functions for displaying the custom traits is called from the onDrawTraits hook
Is every frame called from this hook enough do you think?
I had considered running the updateChampionTraits func every frame from an independent timer, not sure if Id need to if the purpose of this is just to display traits correctly in traits menu

EDIT: actually Id need only call the add / re add func once when the skills menu Apply button is pressed :idea:

Re: Adding skill traits in correct game order

Posted: Sat Jul 18, 2020 7:38 am
by akroma222
SpoilerShow

Code: Select all

function updateTraitOrder(ord)
	local c = party.party:getChampion(ord)
	for k,v in pairs(displayedChampTraitsTab[ord]) do
		if k and v and c:hasTrait(v) then
			c:removeTrait(v)
		end
	end
	for k,v in ipairs(displayedChampTraitsTab[ord]) do
		if k and v and not c:hasTrait(v) then
			c:addTrait(v)
		end
	end
end
Thank you both again, this func works perfectly (called from onDrawTraits hook) and solves my issue 8-)