FG Spreadshirt Swag
  1. #1
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075

    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);
    But the difference here is I was wildcarding the stat but the end fields were pre-known. In the new thing, I just listed the parent node and did * assuming "any changes below" but I do not know if that is ACTUALLY what it means to do that.

    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.

  2. #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.

  3. #3
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Quote Originally Posted by celestian View Post
    Look at the handler option onChildAdd/delete and onChildUpdate. Those should give you some examples doing what you want (from 5E or 2E).
    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>
    If I added handlers for parent for onChildAdd, onChildDelete, onChildUpdate all to same general "updateField()" method, would I trigger if "val2" was change to "valX in <child2>? Ie, does onChildUpdate work for ALL children of a node, whether direct or grandkids? . I assume it has to, otherwise would need to dynamically add listeners on the onChildAdd and remove listeners on onChildDelete if you wanted to onChildChanged for grandkids and doing it on parent did not catch all subs.
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Starfinder Playlist

Log in

Log in