PDA

View Full Version : Number_linked - link source from outside of the windowlist source



MadBeardMan
May 28th, 2017, 00:37
Greetings,

Is there a way to link a 'number_linked' source to a characters value outside of the 'windowlist' they're inside.

For example;

WOiN has a Luck Dice pool, and so I'd like when you allocate the pool to skill, that it sets the Max Value to that of the pool.

Now the skills are on a 2nd tab, and within their own window list, which in turn the datasource is set to .skilllist

Here's the template for the luck dice:


<!-- Luck Dice -->
<number_linked name="luckdice">
<anchored width="30" height="20">
<top offset="2" />
<right parent="rightanchor" anchor="left" relation="relative" offset="-15" />
</anchored>
<frame name="fieldlight" offset="5,5,5,5" />
<tabtarget prev="bonus" next="total" />
<source><name>luckdicepool</name><op>+</op></source>
<script>
function onInit()
local nValue = getValue();
print (nValue);
local nValue2 = DB.getValue(getDatabaseNode().getParent().getParen t().getParent(), "luckdicepool", 0);
setMaxValue(nValue2);
end

function onSourceUpdate()
print ("OnSourceUpdate");
end
</script>
</number_linked>

When that runs, the output shows:


Runtime Notice: Reloading ruleset
Script Notice: 0
Script Notice: 0
Script Notice: 0
Script Notice: 0
Script Notice: 0
Script Notice: 0
Script Notice: 0

Yet in the db.xml, luckdicepool has a value of 3.


<jumpvmodifier type="number">0</jumpvmodifier>
<luckdicepool type="number">3</luckdicepool>
<name type="string">Talik</name>
<notes type="string">Medium sentient humanoid (grade 5; max dice pool 5d6)\n\nActions: 2 (+1 bonus melee attack)</notes>
<perception>
<misc type="number">0</misc>
<skillsdice type="number">1</skillsdice>
</perception>
<perceptionmodifier type="number">0</perceptionmodifier>
<race type="string">Felan</race>
<racelink type="windowreference">
<class>reference_race</class>
<recordname>reference.races.felan@Future Careers</recordname>
</racelink>
<size type="string">Medium</size>
<skilllist>
<id-00001>
<attribute type="string">-</attribute>
<attributed6 type="number">0</attributed6>
<bonus type="number">0</bonus>
<equipment type="number">0</equipment>
<luckdice type="number">0</luckdice>
<name type="string">Stealth</name>
<rank type="number">3</rank>
<rankd6 type="number">2</rankd6>
<text type="formattedtext">
<h>Skill Group</h>
<p>Subterfuge Skills</p>
</text>
<total type="number">2</total>
</id-00001>


So I'm suspecting that because the 'luckdicepool' is a number of levels up (getDatabaseNode().getParent().getParent().getPare nt()) that it can't by default see it, which means in turn why the onSourceUpdate doesn't fire.

Is there anyway to make is 'see' the 'luckdicepool'?

Cheers

Trenloe
May 28th, 2017, 01:11
The source of <number_linked name="luckdice"> is <source><name>luckdicepool</name><op>+</op></source> This is looking at a child of where "luckdice" is within the database (in the onInit code of number_linked.lua). So it can't find "luckdicepool" as the databasenode is not a child of <luckdice> in the database.

You could probably use the relative database notation to traverse up the database hierarchy, see the bottom example here: https://www.fantasygrounds.com/modguide/database.xcp

Also, whereas getDatabaseNode().getParent().getParent().getParen t() will work in terms of going "up" the database, it is inefficient as a databasenode element will be created for each of those getParent() commands. Using the relative DB notation is much more efficient. For example: DB.getValue(getDatabaseNode(), "....luckdicepool", 0);

Use copious amounts of Debug.console("Databasenode name = " .. <databasenode variable>.getNodeName()) to help check exactly where your databasenode variables are pointing to on the database. https://www.fantasygrounds.com/refdoc/databasenode.xcp#getNodeName

MadBeardMan
May 28th, 2017, 01:21
Hello Again!

DB.getValue(getDatabaseNode(), "....luckdicepool", 0);

Works nice.

I'll change the the template to but 'basicnumber' I think.

So if there's a way to 'update' the setMaxValue... oh I know, I can use the ' hasFocus( )' to update the Max Value, going to test that.

Thanks again chap )