PDA

View Full Version : Get inventorylist entry from weaponlist entry



dogfisc
February 28th, 2021, 20:23
I'm trying to figure out how, given a node in a PC's "weaponlist", to get to the linked node in the "inventorylist". The weaponlist has a value called "shortcut":

<shortcut type="windowreference">
<class>item</class>
<recordname>....inventorylist.id-00001</recordname>
</shortcut>
I'm currently doing this:

local sClass, sRecordName = DB.getValue(vWeaponNode, "shortcut");
-- s'sClass: ' | s'item'
-- s'sRecordName: ' | s'charsheet.id-00004.inventorylist.id-Longbow'
local vInvNode = DB.findNode(sRecordName);
-- s'vInvNode: ' | databasenode = { charsheet.id-00004.inventorylist.id-Longbow }
This seems to be easy, and work, but because DB.getValue(vWeaponNode, "shortcut") returns a number of strings, I don't know that I can be certain they will always be consistent, i.e. the second string will contain the path to the inventorylist node.
Does the above code seem reasonable, or is there a safer way to go about it?

Varsuuk
February 28th, 2021, 21:29
I hope someone with more expertise chimes in but I have always done thusly:

For an entry like:


<pcclasslink type="windowreference">
<class>pcclass</class>
<recordname>referencepcclass.fighter@MCSWWB</recordname>
</pcclasslink>


I do:


function onClassLevelChanged(nodeChar)
local _, sPCClassRecord = DB.getValue(nodeChar, "pcclasslink")
Debug.console(DB.getValue(nodeChar, "pcclasslink"))
local sClassID = NodeUtils.getLeafNameFromRecord(sPCClassRecord)
...


The print I added above shows:


Runtime Notice: s'pcclass' | s'referencepcclass.fighter@MCSWWB'



I just do not recall where I looked to see this - probably in other code but it is possible I got it from the Wiki.
So... yeah - I believe with near certainty you are doing it right :)

Moon Wizard
March 2nd, 2021, 21:40
@dogfisc,

For the D&D rulesets, that's typically how weapons are set up. Each weapon record is created when a weapon item is added to a character; and removed when the weapon item is removed from a character. The value in the "shortcut" data is the 'link' between the two. This may not be the case in other rulesets, though most copy from the D&D ones.

Also, you should note that weapon entries can be created independently as well; in which case the "shortcut" data will be empty.

Regards,
JPG

dogfisc
March 2nd, 2021, 22:13
Thank you both; I’ll go ahead with this then, so far it’s been working. And Moon Wizard, your comment regarding the D&D rulesets made me realize I didn’t include the ruleset I’m working with (Pathfinder 1e.)