Hi i am trying to create a macro in foundry that looks for a health potion within an selected actor’s inventory, if its found i will do something to expend it as a use, if not found then return an error to foundry. The code i have below is how far i have got but it’s returning the error despite the item being in the actor’s inventory.
Can anyone point me in the correct direction?
main()
async function main() {
// Is a token selected? If not, error
console.log("Tokens: ", canvas.tokens.controlled)
if(canvas.tokens.controlled.length == 0 || canvas.tokens.controlled.length > 1){
ui.notifications.error("Please select a single token")
return;
}
let actor = canvas.tokens.controlled[0].actor
console.log(actor)
// Does the token have a health potion?
let healthpotion = actor.items.find(item => item.value == "Potion of Greater Healing")
console.log(healthpotion)
if(healthpotion == null || healthpotion == undefined){
ui.notifications.error("No Health Potions left");
return;
}
From the console i can see the potion in the array but my code isn’t finding it.
2
Answers
Thanks ooshp,
I have the answer, i needed to drop the .value and just have item.name, spent hours on this
I haven’t used Foundry in a long time, but it looks like you want this part:
to be this:
Also keep in mind you can log inside a loop if you’re not familiar with what you’re iterating through, to make debugging easier: