-
January 27th, 2020, 02:03 #1
How to add handlers for a parent node and sub nodes
I have a question, I won't be at the point of editing the values in this sheet for a bit and I wanted to adjust to get it as close to right as possible the first time.
My idea is that if either ANYTHING within the <attacks> list changes, like if we add <claw> ... </claw> or the name subentry of <bite> changes or damage changes etc, that the "updateAttacks_text()" method would be called and I could recreate the string.
But I am not sure, in the past for my character sheet, I did things like this:
Code:DB.addHandler(DB.getPath(nodeChar, "abilities.*.baseracemod"), "onUpdate", updateAbilityScore); DB.addHandler(DB.getPath(nodeChar, "abilities.*.baseautomod"), "onUpdate", updateAbilityScore); DB.addHandler(DB.getPath(nodeChar, "abilities.*.score"), "onUpdate", updateAbilityScoreDependencies);
In this lua file I did:
DB.addHandler(DB.getPath(nodeChar, "attacks.*"), "onUpdate", updateAttacks_text);
For example, a single attack type list:
Code:<attacks> <bite> <name type="string">Bite</name> <damage type="string">1d6</damage> <numberOfAttacks type="number">1</numberOfAttacks> </bite> </attacks>
Why would I need to handle in order to get all updates both below <attacks> (ie, adding or removing entries) and inside a specific entry like <bite>'s subfields?
Do I need instead a more verbose?:
DB.addHandler(DB.getPath(nodeChar, "attacks.*"), "onUpdate", updateAttacks_text);
DB.addHandler(DB.getPath(nodeChar, "attacks.*.name"), "onUpdate", updateAttacks_text);
DB.addHandler(DB.getPath(nodeChar, "attacks.*. damage"), "onUpdate", updateAttacks_text);
DB.addHandler(DB.getPath(nodeChar, "attacks.*. numberOfAttacks"), "onUpdate", updateAttacks_text);
or even THIS?
Code:DB.removeHandler(DB.getPath(nodeChar, "attacks.*"), "onUpdate", updateAttacks_text); DB.removeHandler(DB.getPath(nodeChar, "attacks.*.*"), "onUpdate", updateAttacks_text); DB.removeHandler(DB.getPath(nodeChar, "specialabilities.*"), "onUpdate", updateSpecialAbilities); DB.removeHandler(DB.getPath(nodeChar, "specialabilities.*.name"), "onUpdate", updateSpecialAbilities);
Last edited by Varsuuk; January 27th, 2020 at 02:29.
-
January 27th, 2020, 03:41 #2
Look at the handler option onChildAdd/delete and onChildUpdate. Those should give you some examples doing what you want (from 5E or 2E).
---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
January 27th, 2020, 04:40 #3
Awesome - thank you! So thankful you responded quickly so I can fix it up before propagating the wrong way to do it to other files
I haven't yet checked the 2E/5E usage, but went immediately to the DB API to look (what I should have done immediately, but that's what I get for copying stuff "cos that's how it was where I looked" and not thinking about other possible options to "onUpdate" if there is an "onUpdate" there probably are more types, duh)
Code:* [onAdd] parameters = (nodeAdded) --> Add a new node * [onCategoryChange] parameters = (nodeChanged) --> Didn't look into it, but recall there is a "category" thing on some pulldowns so assume it is what it sounds, you edited a node to change categories. Not sure how/why that happens live but once I look at categories it may become obvious. * [onChildAdded] parameters = (nodeParent, nodeChildAdded) --> Nice, this one lets me know when a new node is added. So I would def use that for what I wanted in addition to others. * [onChildCategoriesChange] parameters = (nodeParent) --> Guessing same as other category thing, except for a Childe of a parent node * [onChildDeleted] parameters = (nodeParent) --> Similarly to adding, we can watch (and should if looking at adding) when a node is removed. * [onChildUpdate] parameters = (nodeParent, nodeChildUpdated) --> The third one I suppose I will need - this one triggers when a value in a child node is updated, but not for adding or deleting said child node - right? * [onDelete] parameters = (nodeToBeDeleted) --> Alert to a about to be deleted node. In theory, I guess you can both listen for deletes on a parent and on the specific child node and end up with two events - silly as that may be to do. * [onIntegrityChange] parameters = (nodeChanged) --> Not sure what this one is, can anyone explain? Did a scan and it only appears in CoreRPG for masterindex... I guess it is a plumbing event - is there a use for it in "normal" rulesets? * [onUpdate] parameters = (nodeUpdated) --> Value of a node changed.
EDIT1: Just to be clear, does onChildUpdate trigger for only changes, not additions/deletions?
EDIT2: If I handle on parent node Child Add/Delete + Update, using the following setup:
Code:<parent> <child1> <subchild1 type="string">val1</subchild1> <subchild2 type="string">val2</subchild2> </child1> <child2> <subchild1 type="string">val1</subchild1> <subchild2 type="string">val2</subchild2> </child2> </parent>
Last edited by Varsuuk; January 27th, 2020 at 05:21.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks