PDA

View Full Version : DB.handler trying to set DB value its watching



SilentRuin
June 26th, 2020, 04:16
I'm trying to set the state of something inside the handler that I'm actually watching and clicking on a button that triggers all this.



function onInit()
DB.addHandler("charsheet.*.inventorylist.*.carried", "onUpdate", onCarriedChanged);
end

function onCarriedChanged(nodeCarried)
... stuff to decide when to do this...
DB.setValue(nodeCarried, "carried", "number", 2);
... stuff...
end


But even though it appears to work - it does not actually prevent the button from changing. In fact the logs show it comes back into this function with the button setting unaffected.

Is there a way instead of trying to force a setting to "not happen" by overriding its DB entry directly like I am now - to simply set the button through code to what I want and somehow get it to work?

There is some sort of sequence going on here that is preventing this from actually working - even though it appears to do it and immediately set it back to what it was heading for. In my case, preventing equipped from becoming unequipped.

SilentRuin
June 26th, 2020, 04:57
Never mind... solved it.

Test chunk to prove I could do my elablorate logic here - not that I would ever get rid of 0!!!!



<root>
<windowclass name="char_invitem" merge="join">
<sheetdata>
<button_char_inv_carried name="carried" merge="join">
<script>
function onInit()
onValueChanged();
end

function onValueChanged()
Debug.console(getValue());
if getValue() == 0 then
setValue(1);
end
end
</script>
</button_char_inv_carried>
</sheetdata>
</windowclass>
</root>