FG Spreadshirt Swag
  1. #1

    Understanding DB.handler and onChildDeleted

    Hi,

    I think I have to ask in a new thread, instead in my ruleset thread. Makes more sense.

    I have a windowlist (name: armorlist, data source: .inventorylist), which I can populate with items.
    When adding items, a script (called soak), is activated and it goes through all the items in the armorlist and adds the sums together and allocates them to the correct place.

    It works fine with an onInit function, and onValueChanged function, but when deleting an item, nothing happens.

    I should say that onInit is placed in a window above the armorlist. And the onValueChanged is in the items I add to the armorlist. I had to do it like that to make the onInit to function.

    Anyway, I think I need a handler function here. More specifically onChildDeleted. But I have no understanding of how they work.
    And after going through the developer guide and forums, I think I found the solution, but I don't understand it at all.

    This is what I have so far:

    Code:
    function onInit()
    local nodeWin = getDatabaseNode();
    	
    DB.addHandler("inventorylist", "onChildDeleted", soak);
    
    soak(nodeWin);
    end
    But this doesn't work. I need the soak function to run when an item is deleted. And now I don't know what the next step would be.

    Any help or guidance would be greatly appreciated.

  2. #2
    The DB.addHandler expects an absolute database path (not a relative database path).

    An example from CoreRPG inventory list script:
    Code:
    function onInit()
    	local node = getDatabaseNode();
    	DB.addHandler(DB.getPath(node, "*.carried"), "onUpdate", onCarriedChanged);
    end
    
    function onClose()
    	local node = getDatabaseNode();
    	DB.removeHandler(DB.getPath(node, "*.carried"), "onUpdate", onCarriedChanged);
    end
    Regards,
    JPG

  3. #3
    Thank you for a very quick answer.

    This is very advanced for me right now, so I don't understand what I am doing, but trying.
    So, I need to add DB.getPath to point directly at the list? How does DB.getPath(node, "*.carried") do this? I don't really understand how this finds the list.

    I guess I need to write DB.addHandler(DB.getPath(nodeWin," SOMETHING"), "onChildeDeleted", soak)

    But what would I need to write in SOMETHING to find the inventorylist? Like; DB.getPath(nodeWin, "*.inventorylist")

    Sorry if I ask simple questions, but I just don't understand how things connect with the different commands.

  4. #4
    An absolute path means that you are explicitly specifying the entire path from the root of the database to the specific value that you want to access/monitor. That's why you can't just specify "inventorylist" as the first parameter; because it needs the full path of the character inventory list (charsheet.id-00004.inventorylist).

    Try this (assuming your script is associated with the windowlist control that handles your inventory list):
    Code:
    DB.addHandler(DB.getPath(getDatabaseNode()), "onChildDeleted", soak);
    Depending on the rest of your code and how it is updating "soak", you may need to add something like this (depending on what the soakfield name is in the item records).
    Code:
    	DB.addHandler(DB.getPath(getDatabaseNode(), "*.soakfield"), "onUpdate", soak);
    The encumbrance code in a lot of rulesets works similarly, since it needs to monitor carried/weight fields, and also handle item deletion.

    Regards,
    JPG

  5. #5
    Thank you so much! That explanation, plus a little trial and error, not only made it work, but also made me understand about 70 % of what it did!

    I had to move the soak function into the windowlist with the handler, but it worked!

    Again, thanks!

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
  •  
5E Character Create Playlist

Log in

Log in