PDA

View Full Version : How to activate multiple CT Sections when an actor becomes Active



ronnke
January 24th, 2024, 12:34
I'm trying to activate/visible multiple CT_Sections when the combat tracker switches to the active CT Actor.

I know you can declare a button in your ct_host_entry.xml as <button_ct_section_active> and pair it with a <sub_ct_section> and this will work. My problem is I want to activate 2 sections on the Actors turn.

I've tried creating a DB.addHandler to my ct_entry.lua trigger:



-- ct_entry.lua

function onInit()
super.onInit();

-- unrelated stuff deleted

DB.addHandler(DB.getPath(getDatabaseNode(), "active"), "onUpdate", self.onUpdateActive);
end

function onUpdateActive(nodeField)
local bState = (nodeField.getValue() == 1);

sub_stats.setVisible(bState);
sub_combat.setVisible(bState);
end



Likewise with overriding onActiveChanged in my ct_entry.lua and trying each of the commented methods:


-- ct_entry.lua

function onActiveChanged()
Debug.chat("ct_entry.lua -- onActiveChanged");
local bState = (DB.getValue(getDatabaseNode(), "active", 0) == 1);
Debug.chat(bState);

-- self.onSectionChanged("stats");
-- self.onSectionChanged("combat");

-- super.onSectionChanged("stats");
-- super.onSectionChanged("combat");

-- sub_stats.setVisible(bState);
-- sub_combat.setVisible(bState);
end


I've messed around with all sorts of stuff, without success. I need some guidance here. Help!

Moon Wizard
January 24th, 2024, 19:35
You'll need to update ct_entry.lua to override a couple functions:



function onActiveChanged()
self.onSectionChanged("stats");
self.onSectionChanged("combat");
end
function getSectionToggle(sKey)
local bResult = false;

local sButtonName = "button_section_" .. sKey;
local cButton = self[sButtonName];
if cButton then
bResult = (cButton.getValue() == 1);
if ((sKey == "stats") or (sKey == "combat")) and self.isActive() and not self.isPC() then
bResult = true;
end
end

return bResult;
end


Regards,
JPG

ronnke
January 24th, 2024, 20:57
Thanks! That did it.

ronnke
January 24th, 2024, 21:08
For future proofing would there be a need to implement some consideration for the parent functions? ie super.onActiveChanged()

Moon Wizard
January 24th, 2024, 22:51
Not in this case; because you want to override the default behavior completely.

JPG