celestian
July 8th, 2017, 20:20
I've been debugging a issue that has been perplexing. I've a feeling this is related to modules somehow but can't wrap my head around a solution.
Right now when I add a weapon to a NPC that is LOCAL to the campaign everything works fine.
When I load a NPC from a module (NOT a read only module) and adjust it to have a weapon (adds feather to it in list at this point) the damagelist does not show properly until I close and reopen the NPC. Keep in mind the damagelist is actually there because I can execute a damage roll and it works. Any pre-existing weapons/damage in the module show/work fine except as noted below in "addHandler".
So, all that sounds kinda vague and confusing so here is some debug code that might help. This snippet of debug is from me dropping a weapon on the NPC and it being added and then the char_weapon.lua:onInit->onDataChanged() being run.
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'nodeWeapon' | databasenode = { npc.id-00746.weaponlist.id-00003@2e Monsters }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'nodeChar' | databasenode = { npc.id-00746@2e Monsters }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'rActor' | { s'sType' = s'pc', s'sCreatureNode' = s'npc.id-00746@2e Monsters', s'sCTNode' = s'', s'sName' = s'Barghest' }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDamage' | { }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDamageNodes' | { }
As you can see there is no aDamageNodes, remember that for the next one.
For this bit of debug I just closed the above NPC and re-opened it and you can see those values missing above are no longer missing.
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'nodeWeapon' | databasenode = { npc.id-00746.weaponlist.id-00003@2e Monsters }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'nodeChar' | databasenode = { npc.id-00746@2e Monsters }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'rActor' | { s'sType' = s'pc', s'sCreatureNode' = s'npc.id-00746@2e Monsters', s'sCTNode' = s'', s'sName' = s'Barghest' }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDamage' | { }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDamageNodes' | { #1 = databasenode = { npc.id-00746.weaponlist.id-00003.damagelist.id-00001@2e Monsters }, #2 = databasenode = { npc.id-00746.weaponlist.id-00003.damagelist.id-00002@2e Monsters } }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDice' | { #1 = s'd6' }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'sDamage1' | s'1d6 bludgeoning'
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'sDamage2' | s'1d6 bludgeoning'
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDice' | { #1 = s'd3' }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'sDamage1' | s'1d3 bludgeoning'
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'sDamage2' | s'1d3 bludgeoning'
I've also noticed that the "addHandler" "onDataChanged" configuired in the onInit() for a node's weaponlist doesn't seem to trigger (even tho it's added it) on a module NPC at all. Normally when I edit a weapon's damage the damagestring is updated as I do it... it's not adjusted at all. When I do the same thing to a local NPC it works as expected.
DB.addHandler(node.getNodeName(), "onChildUpdate", onDataChanged);
Here is the function I'm getting the above debug for tho I don't think it'll be much help. I've bolded the section where the value is coming back different.
function onDamageChanged()
local nodeWeapon = getDatabaseNode();
local nodeChar = nodeWeapon.getChild("...")
local rActor = ActorManager.getActor("pc", nodeChar);
local sBaseAbility = "strength";
if type.getValue() == 1 then
sBaseAbility = "dexterity";
end
local aDamage = {};
local aDamageNodes = UtilityManager.getSortedTable(DB.getChildren(nodeW eapon, "damagelist"));
for _,v in ipairs(aDamageNodes) do
local nMod = DB.getValue(v, "bonus", 0);
local sAbility = DB.getValue(v, "stat", "");
if sAbility == "base" then
sAbility = sBaseAbility;
end
if sAbility ~= "" then
nMod = nMod + ActorManager2.getAbilityBonus(rActor, sAbility, "damageadj");
end
-- add in prof modifiers
nMod = nMod + getToDamageProfs(nodeWeapon);
local aDice = DB.getValue(v, "dice", {});
if #aDice > 0 or nMod ~= 0 then
local sDamage = StringManager.convertDiceToString(DB.getValue(v, "dice", {}), nMod);
local sType = DB.getValue(v, "type", "");
if sType ~= "" then
sDamage = sDamage .. " " .. sType;
end
-- do this to make splitting up damage rolls,
-- for small/medium and large type damage style of AD&D viable -celestian
DB.removeHandler(nodeWeapon.getNodeName(), "onChildUpdate", onDataChanged);
DB.setValue(v, "damageasstring","string",sDamage);
DB.addHandler(nodeWeapon.getNodeName(), "onChildUpdate", onDataChanged);
--
end
end
end
Is there some odd behavior in the way modules entries and local copies work? Is there a solution to where I can avoid having to have a local the NPC to get the right values?
Right now when I add a weapon to a NPC that is LOCAL to the campaign everything works fine.
When I load a NPC from a module (NOT a read only module) and adjust it to have a weapon (adds feather to it in list at this point) the damagelist does not show properly until I close and reopen the NPC. Keep in mind the damagelist is actually there because I can execute a damage roll and it works. Any pre-existing weapons/damage in the module show/work fine except as noted below in "addHandler".
So, all that sounds kinda vague and confusing so here is some debug code that might help. This snippet of debug is from me dropping a weapon on the NPC and it being added and then the char_weapon.lua:onInit->onDataChanged() being run.
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'nodeWeapon' | databasenode = { npc.id-00746.weaponlist.id-00003@2e Monsters }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'nodeChar' | databasenode = { npc.id-00746@2e Monsters }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'rActor' | { s'sType' = s'pc', s'sCreatureNode' = s'npc.id-00746@2e Monsters', s'sCTNode' = s'', s'sName' = s'Barghest' }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDamage' | { }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDamageNodes' | { }
As you can see there is no aDamageNodes, remember that for the next one.
For this bit of debug I just closed the above NPC and re-opened it and you can see those values missing above are no longer missing.
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'nodeWeapon' | databasenode = { npc.id-00746.weaponlist.id-00003@2e Monsters }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'nodeChar' | databasenode = { npc.id-00746@2e Monsters }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'rActor' | { s'sType' = s'pc', s'sCreatureNode' = s'npc.id-00746@2e Monsters', s'sCTNode' = s'', s'sName' = s'Barghest' }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDamage' | { }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDamageNodes' | { #1 = databasenode = { npc.id-00746.weaponlist.id-00003.damagelist.id-00001@2e Monsters }, #2 = databasenode = { npc.id-00746.weaponlist.id-00003.damagelist.id-00002@2e Monsters } }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDice' | { #1 = s'd6' }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'sDamage1' | s'1d6 bludgeoning'
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'sDamage2' | s'1d6 bludgeoning'
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'aDice' | { #1 = s'd3' }
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'sDamage1' | s'1d3 bludgeoning'
Runtime Notice: s'char_weapon.lua' | s'onDamageChanged' | s'sDamage2' | s'1d3 bludgeoning'
I've also noticed that the "addHandler" "onDataChanged" configuired in the onInit() for a node's weaponlist doesn't seem to trigger (even tho it's added it) on a module NPC at all. Normally when I edit a weapon's damage the damagestring is updated as I do it... it's not adjusted at all. When I do the same thing to a local NPC it works as expected.
DB.addHandler(node.getNodeName(), "onChildUpdate", onDataChanged);
Here is the function I'm getting the above debug for tho I don't think it'll be much help. I've bolded the section where the value is coming back different.
function onDamageChanged()
local nodeWeapon = getDatabaseNode();
local nodeChar = nodeWeapon.getChild("...")
local rActor = ActorManager.getActor("pc", nodeChar);
local sBaseAbility = "strength";
if type.getValue() == 1 then
sBaseAbility = "dexterity";
end
local aDamage = {};
local aDamageNodes = UtilityManager.getSortedTable(DB.getChildren(nodeW eapon, "damagelist"));
for _,v in ipairs(aDamageNodes) do
local nMod = DB.getValue(v, "bonus", 0);
local sAbility = DB.getValue(v, "stat", "");
if sAbility == "base" then
sAbility = sBaseAbility;
end
if sAbility ~= "" then
nMod = nMod + ActorManager2.getAbilityBonus(rActor, sAbility, "damageadj");
end
-- add in prof modifiers
nMod = nMod + getToDamageProfs(nodeWeapon);
local aDice = DB.getValue(v, "dice", {});
if #aDice > 0 or nMod ~= 0 then
local sDamage = StringManager.convertDiceToString(DB.getValue(v, "dice", {}), nMod);
local sType = DB.getValue(v, "type", "");
if sType ~= "" then
sDamage = sDamage .. " " .. sType;
end
-- do this to make splitting up damage rolls,
-- for small/medium and large type damage style of AD&D viable -celestian
DB.removeHandler(nodeWeapon.getNodeName(), "onChildUpdate", onDataChanged);
DB.setValue(v, "damageasstring","string",sDamage);
DB.addHandler(nodeWeapon.getNodeName(), "onChildUpdate", onDataChanged);
--
end
end
end
Is there some odd behavior in the way modules entries and local copies work? Is there a solution to where I can avoid having to have a local the NPC to get the right values?