Outputting a variable number of table images

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
busterbluth
Cave Troll
Posts: 30
Joined: Sat Aug 17, 2019 3:49 pm

Outputting a variable number of table images

Post by busterbluth »

HI,

I'm really green with mixing HTML with macro code. I've got a simple macro that works great:

Code: Select all


[h: visDie = eval("1d12")]
<img src='[r:tblImage("TwelveSide",visDie)]'>

Does anyone know how I can build on this to output a variable number of dice? If I need another d12 roll, how would I do that?

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Outputting a variable number of table images

Post by aliasmask »

It depends on if you want them rolled individually or all together. So, if you want to make multiple rolls on the same table, you would need that number.

Code: Select all

[H: abort(input("numRolls|1|Number of Rolls|Text"))]
[H: output = ""]
[H: template = '<img src="%{visDie}" />']
[H, c(numRolls), code: {
   [H: visDie = tblImage("TwelveSide",1d12)]
   [H: output = json.append(output,strformat(template))]
}]

[R: json.toList(output," ")]

busterbluth
Cave Troll
Posts: 30
Joined: Sat Aug 17, 2019 3:49 pm

Re: Outputting a variable number of table images

Post by busterbluth »

Thank you so much!

Post Reply

Return to “Macros”