#got it, thanks, that'll get me looking
1 messages · Page 1 of 1 (latest)
I think my issue is actually not so much related to the item not cloning properly, but rather when I then try to use createEmbeddedDocuments on the target and pass it that item, it'll create it but not its contents, and I think it may be because the content items' permissions don't get update in this way?
Basically, I'm trying to find a way to take an existing container from one token and clone it to another actor. I can easily clone over the container itself, but its contents get lost.
containers don't actually contain items
they just contain a list of ids of items that 'are in' that container, and then the sheet rendering makes it look like that
right
there's no actual items-inside-items in foundry
so how would i accomplish the ask of cloning a container and the list of item ids in it?
Create the new container and then loop through the items, clone each, and put them into the new container?
yep, i'd think so
I was afraid of that
and since the new items will have new ids, also double check at the end that it all lines up. you can create with {keepId: true} but better to just assume they'll change, catch them, then update the container, more resilient that way
You wouldn't happen to know how to update the container's list of items contents, would you? I have successfully created the new container at the destination, created all the new items that were "in" the source container, and they currently just show in the destination inventory. How would I update the container to "move" the items into it (link it to the container). Directly setting the container.system.contents seems forbidden. Cannot set property contents of #<ContainerData> which has only a getter
create the items first, then create the container with the ids. you might have to do like
const containerData = sourceContainer.toObject();
const newItems = target.createEmbedded....
containerData.system.contents = newItems.map(d => d.id);
// then createEmbedded with containerData
and the nested data models may make it more complicated than that
take a look through https://foundryvtt.wiki/en/development/api/DataModel if you haven't, and also check the source of your systtem for what a ContainerData object looks like internally, maybe it has a set method
this isn't pf2e, which is the only system i'm specifically familiar with, so you're on your own from here, ask back in the main channel if you get stuck