-
January 12th, 2019, 06:01 #1
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
Combat Tracker and related questions
I am working on some PF2 stuff, and I need to be able to delete a PC from the CT using code. To my surprise, there is not a Combat Manager call to remove an entity from the CT, although there is code to add an entity. There is, however, code to intercept the deletion of a node from the list in the database node that constitutes the CT entities. The relevant code I have gathered belowor maybe I am still missing some relevant code somewhere?)
Code:function onDesktopInit() DB.addHandler(CT_COMBATANT_PATH, "onDelete", onDeleteCombatantEvent); ... DB.addHandler("charsheet.*", "onDelete", onCharDelete); end local aCustomDeleteCombatantHandlers = {}; function setCustomDeleteCombatantHandler(f) table.insert(aCustomDeleteCombatantHandlers, f); end function removeCustomDeleteCombatantHandler(f) for kCustomDelete,fCustomDelete in ipairs(aCustomDeleteCombatantHandlers) do if fCustomDelete == f then table.remove(aCustomDeleteCombatantHandlers, kCustomDelete); return true; end end return false; end function onDeleteCombatantEvent(nodeCT) for _,fCustomDelete in ipairs(aCustomDeleteCombatantHandlers) do if fCustomDelete(nodeCT) then return true; end end return false; end function onCharDelete(nodeChar) local nodeCT = getCTFromNode(nodeChar); if nodeCT then DB.setValue(nodeCT, "link", "windowreference", "npc", ""); end end
1.onDelete for the deleted node.
2.(if there is a parent node)onChildDeleted for the parent of the node.
I figured that had to be the case because something somewhere had to fire the onDelete handler. So, a few follow-on questions ensue:
1. What is the order that those two delete events/handlers fire?
2. In the code above that traps the onDelete event, it is interesting that it is looking for a registered function that returns a true value, in which case it doesn't call any further registered functions. What happens when that function result gets back to the FG engine. Does returning false override the deletion of the node? If the function result matters on any of the handlers then the API docs needs to be changed to reflect the guidance for handler function results.
Finally, what I'd really like to know, aside from these academic questions, is what is the recommended method to remove a CT participant from code when the need arises to do so? Should I just go delete the combattracker.list child and somewhere I couldn't find (perhaps some code buried in an xml script) the CT interface will get magically updated?
-
January 12th, 2019, 07:24 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
If you need to delete a database node in the code, just call: databasenode.delete() OR DB.deleteNode(databasenode/path)
The current order of events is:
databasenode.onDelete
DB handler "onDelete" event
databasenode.onChildDeleted
DB handler "onChildDeleted" event
I wouldn't want to guarantee ordering of the code at this point given the work we are doing, so you should assume ordering can be changed.
Regards,
JPG
-
January 12th, 2019, 12:57 #3
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
MW, just to close the loop then: in order to remove an NPC or PC from the CT, the recommended method is to delete the combattracker.list node for that PC or NPC and let the event trappers manage the consequences?
Also, please confirm that the return results of handlers are ignored by FG engine (i.e. the use of the true/false result in the code quoted above is only to bypass all but the first registered handler that returns true).
Thanks.
-
January 13th, 2019, 03:34 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
The correct way is to delete the combatant node. Any code that you want to trigger off of a combatant being deleted should be built using handlers like most of the example code does.
Return values for handlers are always ignored.
Regards,
JPG
-
January 13th, 2019, 04:52 #5
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
Thank you, sir.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks