PDA

View Full Version : Adding the results of a Windowlist together.



Oberoten
January 27th, 2008, 10:58
I am trying to get this to autocalculate the values of Xpused in this one for all instances of a windowlist. Of course... this one doesn't work as well as it should. (It gives the wrong final calculations for some reason. Meh)

So I am thinking there should likely be a more useful version of this if I used pairs... But I am knackered if I can figure that one out either.







function onValueChanged()
local test;
local cost;
cost = window.getDatabaseNode().getChild("skill.cost").getValue()
test = window.getDatabaseNode().getChild("skill.level").getValue()
window.getDatabaseNode().getChild("skill.xp").setValue( cost*((test^2)/2 +(test/2)) );


local xp1;
local xp2;
local xp3;
local xpdiff;
xp1 = window.getDatabaseNode().getChild("skill.xp").getValue()
xp2 = window.getDatabaseNode().getChild("skill.oldxp").getValue()
xp3 = window.windowlist.window.getDatabaseNode().getChil d("xpused").getValue()
xpdiff = xp3+ (xp1 - xp2)
window.windowlist.window.getDatabaseNode().getChil d("xpused").setValue(xpdiff);
window.getDatabaseNode().getChild("skill.oldxp").setValue(xp1);
end

Oberoten
January 27th, 2008, 11:22
Replacing the whole block of :


local xp1;
local xp2;
local xp3;
local xpdiff;
xp1 = window.getDatabaseNode().getChild("skill.xp").getValue()
xp2 = window.getDatabaseNode().getChild("skill.oldxp").getValue()
xp3 = window.windowlist.window.getDatabaseNode().getChil d("xpused").getValue()
xpdiff = xp3+ (xp1 - xp2)
window.windowlist.window.getDatabaseNode().getChil d("xpused").setValue(xpdiff);
window.getDatabaseNode().getChild("skill.oldxp").setValue(xp1);
end

With


local points = 0;

for k, v in pairs(window.windowlist.getDatabaseNode().getChild ren()) do
if v.getChild("skill.xp") then
points = points + v.getChild("skill.xp").getValue();
end
end
window.windowlist.window.getDatabaseNode().getChil d("xpused").setValue(points);


Didn't just work better, it also added a lot of speed for some reason.