Fenloh
May 23rd, 2010, 17:48
I have a for loop that gets the windows of a windowlist. it works fine when the function is called upon due to a onValueChanged event.
I have added an onInit()-super.onInit() that calls the event. when the onInit calls the function the last windowlist Item is not being processed, while the onValueChanged runns through it correctly.
Any Ideas why that happens? Here is the code.
Fenloh
Example:
Armor1 (1) (2) (active)
Armor2 (2) (2) (inactive)
Armor3 (10) (11) (active)
result after onValueChanged(): (11) (13)
Result after onInit(); (1) (2)
If an empty armoritem would follow, then the result would be correct.
function onInit()
super.onInit();
window.windowlist.addArmorvalue();
end
function onValueChanged()
window.windowlist.addArmorvalue();
end
function addArmorvalue()
local balisticvalue = 0
local impactvalue = 0
for k, v in ipairs(getWindows()) do
local armorisactive = v.getDatabaseNode().getChild("armorisactive").getValue();
if armorisactive == 1 then
balisticvalue = balisticvalue + v.getDatabaseNode().getChild("armor.balistic").getValue();
impactvalue = impactvalue + v.getDatabaseNode().getChild("armor.impact").getValue();
end
end
window.getDatabaseNode().getChild("armor.hiddenbalisticvalue").setValue(balisticvalue);
window.getDatabaseNode().getChild("armor.hiddenimpactvalue").setValue(impactvalue);
end
I have added an onInit()-super.onInit() that calls the event. when the onInit calls the function the last windowlist Item is not being processed, while the onValueChanged runns through it correctly.
Any Ideas why that happens? Here is the code.
Fenloh
Example:
Armor1 (1) (2) (active)
Armor2 (2) (2) (inactive)
Armor3 (10) (11) (active)
result after onValueChanged(): (11) (13)
Result after onInit(); (1) (2)
If an empty armoritem would follow, then the result would be correct.
function onInit()
super.onInit();
window.windowlist.addArmorvalue();
end
function onValueChanged()
window.windowlist.addArmorvalue();
end
function addArmorvalue()
local balisticvalue = 0
local impactvalue = 0
for k, v in ipairs(getWindows()) do
local armorisactive = v.getDatabaseNode().getChild("armorisactive").getValue();
if armorisactive == 1 then
balisticvalue = balisticvalue + v.getDatabaseNode().getChild("armor.balistic").getValue();
impactvalue = impactvalue + v.getDatabaseNode().getChild("armor.impact").getValue();
end
end
window.getDatabaseNode().getChild("armor.hiddenbalisticvalue").setValue(balisticvalue);
window.getDatabaseNode().getChild("armor.hiddenimpactvalue").setValue(impactvalue);
end