I have below macro in FoundryVTT13. When I execute it, I'm getting rendered list of…
- User
I have below macro in FoundryVTT13. When I execute it, I'm getting rendered list of rolls, instead of list of numbers (parameters:
content). When I removerolls: rolled,from chat message data, I'm getting list of numbers, but DiceSoNice doesn't show animation. How to get just list of number and rolled dice? Assistant
Of course! This is a classic and excellent question that demonstrates a core interaction in the Foundry VTT API. You've correctly identified the conflict:
- The
rollsproperty in a chat message is what triggers Dice So Nice. - A chat message with
type: CONST.CHAT_MESSAGE_TYPES.ROLLtells Foundry to ignore your customcontentand instead render therollsarray using its default template.
You need to give the
rollsdata to Dice So Nice without letting Foundry's default roll template take over the chat message's appearance.Here are two effective ways to solve this.
Solution 1: The Best and Simplest Method
The easiest fix is to change the chat message
type. By setting the type to something other thanROLL(likeICorOOC), you tell Foundry to render yourcontentas-is, while still including therollsproperty for Dice So Nice to see.Here is your macro, corrected with this simple change.
/* * RECOMMENDED SOLUTION * This macro rolls 4d6, displays only the numeric results in a list, * and triggers the Dice So Nice animation. */ (async () => { // 1. Perform the roll const roll = await new Roll('4d6').evaluate({ async: true }); // 2. Extract the results into an array of numbers // A more modern way to get all results from all dice is using flatMap const results = roll.dice.flatMap(d => d.results.map(r => r.result)); // 3. Build your custom HTML content let content_html = `<ul>`; results.forEach(r => { content_html += `<li>${r}</li>`; }); content_html += `</ul>`; // 4. Create the Chat Message let chatData = { user: game.user.id, speaker: ChatMessage.getSpeaker(), content: content_html, // Include the rolls array for Dice So Nice. Note: it must be an array. rolls: [roll], // THE KEY CHANGE: Use a different message type so Foundry displays // your custom 'content' instead of its own roll template. // IC (In Character) or OOC (Out of Character) are good choices. type: CONST.CHAT_MESSAGE_TYPES.IC }; ChatMessage.create(chatData); })();Why this works: Dice So Nice listens for any new chat message that has a
rollsproperty. It doesn't care what the messagetypeis. By changing the type toIC, you get the best of both worlds: Foundry renders your customcontent, and Dice So Nice sees therollsand plays the animation.
Solution 2: Using the Dice So Nice API Directly
This method is slightly more complex but is very powerful. You create your chat message exactly how you want it to look (without the
rollsproperty), and then you separately tell Dice So Nice to play the animation for your roll.This is useful if you want to have animations without creating a chat message at all, or if you want more fine-grained control.
/* * ALTERNATIVE SOLUTION * This uses the Dice So Nice API directly to show the roll. */ (async () => { // 1. Check if Dice So Nice is active if (!game.modules.get("dice-so-nice")?.active) { ui.notifications.warn("Dice So Nice is not active."); return; } // 2. Perform the roll const roll = await new Roll('4d6').evaluate({ async: true }); // 3. Extract results and build your custom HTML const results = roll.dice.flatMap(d => d.results.map(r => r.result)); let content_html = `<ul>${results.map(r => `<li>${r}</li>`).join('')}</ul>`; // 4. Create a standard chat message with your content // Notice there is NO 'rolls' property here. let chatData = { user: game.user.id, speaker: ChatMessage.getSpeaker(), content: content_html }; ChatMessage.create(chatData); // 5. Tell Dice So Nice to show the animation for the roll you made. await game.dice3d.showForRoll(roll); })();Why this works: You are decoupling the chat message creation from the dice animation.
- You create a perfectly formatted chat message with just your numbers.
- You then use the
game.dice3d.showForRoll()function, which is the core of the Dice So Nice API, to trigger the 3D dice for theRollobject you created earlier.
Both methods will give you your desired result: a chat message with just a list of numbers, and a beautiful 3D dice animation. I would recommend Solution 1 for its simplicity.
- The
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.