PDA

View Full Version : setValue question



Zhern
January 3rd, 2017, 02:25
I should be able to set two different node values one after the other, correct? For example:

if(nCurrentScore == 18) then
setValue(nodeWin, "abilities." .. target[1] .. ".damage",2);
setValue(nodeWin, "abilities." .. target[1] .. ".bonus",3);
....

Right? I didn't see anything in the refdoc entries for setValue that would prevent that.

vodokar
January 3rd, 2017, 03:29
I haven't tried it, but as long as they have the same window node, that should be possible. If you are having an issue, it might be with the target[1]. I had several issues dealing with that. You can avoid that by using database handlers instead.

For example.

<template name="number_charabilitychareaction">
<number_abilitybonus>
<anchored position="righthigh" offset="15,0" width="36" height="20" />
<hideonvalue value="0" />
<modifiersize>mini</modifiersize>
<script>
function onSourceUpdate()
local nodeWin = window.getDatabaseNode();
local nCurrentScore = DB.getValue(nodeWin, "abilities.charisma.score", 0);

nReaction = GameSystem.getAbilityChaReaction(nCurrentScore) + calculateSources();
setValue(nodeWin, "abilities.chareaction.bonus", "number", nReaction);
end

function onInit()
local nodeWin = window.getDatabaseNode();
DB.addHandler(DB.getPath(nodeWin, "abilities.charisma.score"), "onUpdate", onSourceUpdate);
super.onInit();
end
</script>
</number_abilitybonus>
</template>

On init, set up database handler to watch the charisma score.
On source update of the charisma score, find the value of the charisma reaction bonus based on the new charisma score.
Set the value of the charisma reaction bonus.

This avoids the use of target[1] and will likely avoid lots of problems because of it, and as Trenloe said the other day, is best to directly work against the database.

Should be no reason using this technique that you can't do two setValue's at once, that I'm aware of.

Zhern
January 3rd, 2017, 03:55
Yeah, I have no issues when I use the DB handler. I'm moving a bunch of stuff over to templates and ran into a bit of a snag but I ended up figuring it out.

Thanks, vodokar!

Trenloe
January 3rd, 2017, 05:30
Assuming you're using DB.setValue (https://www.fantasygrounds.com/refdoc/DB.xcp#setValue)then I don't see any issue with what you've listed.

Zhern
January 3rd, 2017, 13:40
Yep, I am using DB.setValue. Hard to set the value of a node that doesn't exist, though. Took me a bit to realize what I was doing wrong but got it sorted. Thanks, Trenloe!