PDA

View Full Version : onValueChange()



Oberoten
May 21st, 2008, 10:18
onValueChange()

... this stumps me, is there a way to make it look at another value to update THIS field whenever that one updates?

aka...

<numberfield name="field1>
....
</numberfield>

<numberfield name="field2>
....
<script>
onValueChange(field1)
.....
.....
end
</script>
</numberfield>

Oberoten
May 21st, 2008, 10:41
The biggest problem here I think is caused by me using a windowlist...

Oberoten
May 21st, 2008, 10:54
<numberfield name="mstat">
<bounds rect="300,9,35,20" />
<description text="Dexterity" />
<script>

function onInit()
source = window.windowlist.window.getDatabaseNode().getChil d("dexterity")
window.getDatabaseNode().getChild("mstat").setValue(source)
source.onUpdate = onValueChanged
onValueChanged()
end

function onValueChanged()

local a,b,c,d,e;

a = window.windowlist.window.getDatabaseNode().getChil d("dexterity").getvalue();
window.getDatabaseNode().getChild("mstat").setValue(a)

a = window.getDatabaseNode().getChild("abonus").getValue()
b = window.getDatabaseNode().getChild("skill").getValue()
c = window.getDatabaseNode().getChild("mstat").getValue()
d = a+b+c;
window.getDatabaseNode().getChild("Attack").setValue(d)

return true;
end
</script>
</numberfield>

joshuha
May 21st, 2008, 14:12
Sorry can you explain a bit better what you are trying to do?

OnValueChanged is a function that happens when the control (self-referential) changes a value. You seem to be trying to set an update handler to fire off that local event but that doesn't really make sense.

If you are trying to look at another value that when the other value changes it does something then you almost have it. You just need to make your own function instead of using the built in onValueChanged. Call it sourceUpdate or something like that.

Oberoten
May 21st, 2008, 14:41
I just wish to link two fields...
One is inside a windowlist and should always be equal to the other one. (And if it changes it also needs to do the regular OnUpdate thing to update other values within the windowlist instance. )

IE :

The windowlist is the weapon-entry for the character-sheet. You can cram in as many weapons as you wish. But all melee weapons have a bonus equal with the Dexterity of the wielder.

I just want to be able to pull the bonus so it is nicely visible on the charsheet.

Pulling it when I doubleclick the attack is easy, I just call it with

window.windowlist.window.getDatabaseNode().getChil d("dexterity").getValue();

... but I'd much rather have it all update in a nice clean manner.

Foen
May 21st, 2008, 16:42
One way to do this is using the onInit event for your weapon windowclass:



in weapon windowclass:

local dexnode = nil;

function onInit()
dexnode = windowlist.window.getDatabaseNode().getChild("dexterity");
if dexnode then
dexnode.onUpdate = recalc;
recalc();
end
end

function recalc()
if dexnode then
mstat.setValue(dexnode.getValue());
end
end


Is that the sort of thing?

Stuart

Foen
May 21st, 2008, 16:49
Linking it in to your code, mstat could be redefined as a numbercontrol instead of a numberfield, and the mstat script block becomes:



in mstat script block;

function onValueChanged()
local a,b,c;
a = window.getDatabaseNode().getChild("abonus").getValue();
b = window.getDatabaseNode().getChild("skill").getValue();
c = getValue();
window.getDatabaseNode().getChild("Attack").setValue(a+b+c);
return true;
end


Stuart

Oberoten
May 21st, 2008, 17:42
THAT did the trick.
Perfect solution. :)