AmadanNaBriona
March 31st, 2020, 03:04
Another noob question.
I have a stat, adjDX, which is normally equal to DX.
adjDX is reduced by wearing armor. Every piece of armor has a "dexpen" attribute. So basically, I want:
1. For adjDX to default to DX, and change when DX is changed.
2. For adjDX to be adjusted when armor is added to the character.
3. For adjDX to be adjusted when armor is removed from the character.
I have 1 and 2 working, but not 3.
The function below works, when added as a script invoked by the onUpdate() function for the dexterity node on the charsheet, and invoked whenever a new piece of armor is dragged onto the character.
What I haven't figured out how to do is invoke it if a defenselist item is deleted. I've tried various combination of DB.addHandler, e.g. "DB.addHandler(defenselistode, "onUpdate", updateAdjDX)", but (a) it doesn't work; (b) how would I pass the nodeChar node as an argument?
I guess I could add another invocation of the function to the delete button on the equipment sheet? That seems kludgy and so far I haven't gotten it work right.
function updateAdjDX(nodeChar)
local adjdx = 0;
-- First get basic Dexterity --
adjdx = adjdx + DB.getValue(nodeChar, "attributes.dexterity", 0);
defenses = DB.getChild(nodeChar, "combat.defenselist");
if defenses then
for _,defense in pairs(defenses.getChildren()) do
adjdx = adjdx + defense.getChild("dexpen").getValue()
end
end
DB.setValue(nodeChar,"attributes.adjdx","number",adjdx);
end
I have a stat, adjDX, which is normally equal to DX.
adjDX is reduced by wearing armor. Every piece of armor has a "dexpen" attribute. So basically, I want:
1. For adjDX to default to DX, and change when DX is changed.
2. For adjDX to be adjusted when armor is added to the character.
3. For adjDX to be adjusted when armor is removed from the character.
I have 1 and 2 working, but not 3.
The function below works, when added as a script invoked by the onUpdate() function for the dexterity node on the charsheet, and invoked whenever a new piece of armor is dragged onto the character.
What I haven't figured out how to do is invoke it if a defenselist item is deleted. I've tried various combination of DB.addHandler, e.g. "DB.addHandler(defenselistode, "onUpdate", updateAdjDX)", but (a) it doesn't work; (b) how would I pass the nodeChar node as an argument?
I guess I could add another invocation of the function to the delete button on the equipment sheet? That seems kludgy and so far I haven't gotten it work right.
function updateAdjDX(nodeChar)
local adjdx = 0;
-- First get basic Dexterity --
adjdx = adjdx + DB.getValue(nodeChar, "attributes.dexterity", 0);
defenses = DB.getChild(nodeChar, "combat.defenselist");
if defenses then
for _,defense in pairs(defenses.getChildren()) do
adjdx = adjdx + defense.getChild("dexpen").getValue()
end
end
DB.setValue(nodeChar,"attributes.adjdx","number",adjdx);
end