FG Spreadshirt Swag
  1. #1

    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
    This raised some questions about how the handlers work. I searched for where in the CoreRPG there might be a call to DB.deleteNode, which I had believed was the only thing that would invoke the onDelete handler. I found only 4 instances, and they were all in the item manager. So then that got me to thinking that if you delete a node, it must always invoke two events:

    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?

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

  3. #3

    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.

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

  5. #5

    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

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 Product Walkthrough Playlist

Log in

Log in