5E Product Walkthrough Playlist
  1. #1

    How to get charsheet from combat tracker list entry

    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.

    Code:
    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.
    Last edited by skorski; January 31st, 2022 at 15:33.

  2. #2
    There's already a set of functions to do that in CoreRPG:

    Code:
    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

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
  •  
FG Spreadshirt Swag

Log in

Log in