Fixing random token actors from a bad import

Note: this applies only to worlds imported before July 14th.

Disclaimer: This is for advanced users only, and try this at your own risks.

There was a bug in the Forge Importer where if you have an actor which uses “random token images” (also known as “rollable tokens”), then the importer will fail to find the asset associated with the token (since the *.png file doesn’t exist for example) and will not convert the token to use the assets library as it should. This bug will be fixed shortly, but if you have already imported your world and it is currently broken when you try to drop one such actor into a scene, here’s how you can fix it.
Note: it is recommended that you first export your world from the My Foundry page in order to keep a backup of it in case it does not work as intended. It’s also generally good practice to keep backups of your worlds.

From within your world, while logged in as the Forge user who imported the world, press F12 to bring up the browser’s developer console, and paste this code into it :

const forgeUserId = (await ForgeAPI.status()).user;

Actor.update(game.actors.entities.filter(a => a.data.token.randomImg).map(a => {
  if (a.data.token.img.startsWith("worlds/")) 
     return {_id: a.data._id, "token.img": `https://assets.forge-vtt.com/${forgeUserId}/${a.data.token.img}`};
  return null;
}).filter(a => a)).then(() => alert("Done"))

Wait until an alert window appears saying “Done”, then press OK.
That’s it! Verify that your random token actors are now working as expected.