kalannar
July 23rd, 2014, 21:13
I am creating an extension to keep track of player kingdoms. Each kingdom can have a settlement, and when they add values to society i need to update the kingdom value of fame. That works correctly, the only problem i run into is that when i delete a settlement, it calls the update on fame but i guess it happens before the database removes the node because it still thinks the settlement node is there and updates fame based off it. Is there away to tell of a node is marked to be deleted? Or a different way I should be doing this? Here is the code i am using to update fame:
function onInit()
update();
local node = window.getDatabaseNode();
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onUpdate", update);
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onAdd", update);
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onDelete", update);
end
function onClose()
local node = window.getDatabaseNode();
DB.removeHandler(DB.getPath(node, "settlementlist.*.society.total"), "onUpdate", update);
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onAdd", update);
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onDelete", update);
end
function update()
Debug.chat("Called Update on fame society");
local node = window.getDatabaseNode();
local total= 0;
for _,v in pairs(DB.getChildren(node, "settlementlist")) do
Debug.chat(v);
Debug.chat(DB.getValue(v,"society.total",0));
total = total + DB.getValue(v,"society.total",0);
end
if total == 0 then
total = 0
else
total = math.floor(total/10);
end
setValue(total);
end
function onInit()
update();
local node = window.getDatabaseNode();
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onUpdate", update);
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onAdd", update);
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onDelete", update);
end
function onClose()
local node = window.getDatabaseNode();
DB.removeHandler(DB.getPath(node, "settlementlist.*.society.total"), "onUpdate", update);
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onAdd", update);
DB.addHandler(DB.getPath(node, "settlementlist.*.society.total"), "onDelete", update);
end
function update()
Debug.chat("Called Update on fame society");
local node = window.getDatabaseNode();
local total= 0;
for _,v in pairs(DB.getChildren(node, "settlementlist")) do
Debug.chat(v);
Debug.chat(DB.getValue(v,"society.total",0));
total = total + DB.getValue(v,"society.total",0);
end
if total == 0 then
total = 0
else
total = math.floor(total/10);
end
setValue(total);
end