View Full Version : Raising the value of a number control with an onClick function
Visvalor
December 7th, 2009, 23:16
function onClickDown(button, x, y)
window.truestrength.setValue();
end
I have a generic control with that script inside of it and an arrow going up, how does one set to add +1 to a number control with the name "truestrength" so that they click a button to raise their stat.
Also need to subtract from another number control called "statpoints" and make it where it only adds stat points if they have them available :P
joshuha
December 7th, 2009, 23:32
function onClickDown(button, x, y)
window.truestrength.setValue();
end
I have a generic control with that script inside of it and an arrow going up, how does one set to add +1 to a number control with the name "truestrength" so that they click a button to raise their stat.
Also need to subtract from another number control called "statpoints" and make it where it only adds stat points if they have them available :P
This is how I would do it.
function onClickDown(button, x, y)
truestrength = window.getDatabaseNode().getChild("truestrength");
statpoints = window.getDatabaseNode().getChild("statpoints");
truestrength.setValue(truestrength.getValue()+1);
statpoints.setValue(statpoints.getValue()-1);
end
joshuha
December 7th, 2009, 23:38
Also I am guessing at some point you want to not let it go into the negatives.
function onClickDown(button, x, y)
truestrength = window.getDatabaseNode().getChild("truestrength");
statpoints = window.getDatabaseNode().getChild("statpoints");
if statpoints.getValue() > 0 then
truestrength.setValue(truestrength.getValue()+1);
statpoints.setValue(statpoints.getValue()-1);
end
end
Visvalor
December 7th, 2009, 23:42
As always Joshuha comes through!
Woot woot! It works!
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.