How to use meta-bind to dynamically set bind targets

Im struggling to work out how to leverage java script to dynamically select different notes.

What I’m trying to do

I am trying to create an encounter calculator that takes the selection of a monster defined in its own file, and populates some local properties that can be used.

The structure of each monster file is the same and is its own folder monsters/[monster-name].md . The simplified metadata is:

---
monster-name: orc
hp: 55
attack: 4
xp: 120
---

Things I have tried

Selecting the monster is easy
INPUT[suggester(optionQuery("monsters"), useLinks(false)):selectedMonster]

The following works if explicilty referenced as storagePath#property

meta-bind-js-view
{orc#hp} as text
---
return context.bound.text

however the following where selectedMonster = orc fails

meta-bind-js-view
{selectedMonster#hp} as text
---
return context.bound.text

and even if selectedMonster = orc#hp it just returns “orc#hp”

meta-bind-js-view
{selectedMonster#hp} as text
---
return context.bound.text

Any advice would be appreciated on how to structure the js, i know there are potential other solutions using other plugins, but i’d like to at least learn what I’m doing wrong here before moving on.

I came across this post while searching just about everywhere to find a solution to the same problem. I’ve finally made a working solution:

meta-bind-js-view
{selectedMonster} as selectedMonster
---
const mb = engine.getPlugin('obsidian-meta-bind-plugin').api;
const selectedMonster = context.bound.selectedMonster;
const hp = mb.getMetadata(mb.parseBindTarget(`${selectedMonster}#hp`, ""));
return hp

I doubt this is the most elegant solution, but it works for me!

Coming back to this to add another solution in case someone else needs help with this in the future. Below is an example for dynamically creating a VIEW or INPUT element:

meta-bind-js-view
{selectedMonster} as selectedMonster
---
const selectedMonster = context.bound.selectedMonster;
const str = `\`VIEW[{${selectedMonster}#hp}]\``;
return engine.markdown.create(str);

Where can I learn how to do this in Obsidian? I think I’m looking for something similar, however, it will be used for Satisfactory instead where I will have different materials used to create different items. Not sure I will be up to the task but I want to give it a go. How do I make these arrays such as you had orc with different properties?