PDA

View Full Version : How to get charsheet from combat tracker list entry



skorski
January 31st, 2022, 15:05
I'm having trouble using the link node from the combat tracker (combattracker.list.id-#.link). From what I understand, I should be able to use DB.getValue to get the record but I'm failing to do that. I can use some help to figure out what I'm missing here.



local function onCombatantAdded(ctData)

-- The link entry in the DB
-- <link type="windowreference">
-- <class>charsheet</class>
-- <recordname>charsheet.id-00001</recordname>
-- </link>

class, record = DB.getValue(ctData.getPath(), 'link')
Debug.chat( class )
Debug.chat( record )
-- output: link, nil

class, record = DB.getValue(ctData, 'link')
Debug.chat( class )
Debug.chat( record )
-- output: npc, '' <-- (empty string)

end

DB.addHandler(CombatManager.CT_COMBATANT_PATH, "onAdd", onCombatantAdded);




The windowreference class overall is a mystery to me. It's a distinct class, but I can't tell if that's just for the sake of labeling or if there is something distinct about the data type. Are there special properties or member functions on the class? Does the DB work with windowreferences differently than normal nodes?

I know there's something special about it, because the XML elements within the link aren't counted as children. DB.getChildCount returns 0, but I can still get at them using DB.getValue (at least the class). And as I found with my code above, I'll get a different value back if I use the data directly vs. it's path. I'm really shooting in the dark here, I'm finding the data types and dependencies very hard to reason about.

I'm working with 5E at the moment.

Moon Wizard
January 31st, 2022, 16:15
There's already a set of functions to do that in CoreRPG:



local rActor = ActorManager.getActor(nodeCT);
if rActor and ActorManager.isPC(rActor) then
local nodePC = ActorManager.getCreatureNode(rActor);
if nodePC then
-- Do PC specific stuff
end
end


Some notes:

* DB.getValue requires either a single string path as first parameter; or a databasenode and string as the first two parameters. Any additional data will be treated as the "default" value.

* windowreference data nodes return two string values when using getValue; and require two string values when using setValue.

Regards,
JPG