Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Attack with variable number of targets

1509551092

Edited 1509551121
Quinn
Pro
Sheet Author
So, here's my slightly-complex situation. I'm building a character sheet that includes a repeating list of custom techniques that characters can use. I want each tech to have a 'Use Technique' button that auto-rolls the tech, but a technique can have an arbitrary number of targets based on what it does, how many enemies are in range, et cetera. Use Technique is pretty complex - displaying damage, automatically reducing Stamina, checking if it's still on cooldown, et cetera - so it's not just a feed-numbers-in macro. I've made a !tech command in the API that does all the dirty work, and that can take in a list of targets as a parameter (!tech --targets id1 id2 id3).The part I'm having trouble with is getting that list. To my knowledge, there's no way to write a command that prompts the user for an arbitrary number of targets - you just put in the right number of @{target|Name|token_id} blocks, and then roll20 prompts the roller for each one accordingly. I've worked around this by adding a "Targets" field next to the Use Technique button where the user can enter the number of targets they want to hit, and a worker on the character sheet accordingly alters the Use Technique button's backing roll; for example, if Alice sets Targets to 2 on Fireball, then the button's backing roll changes to '!t --as "@{Alice|character_id}" "Fireball" +0 --targets @{target|Target #1|token_id} @{target|Target #2|token_id}". However, even this overengineered method lands me with a really messy UX, because of how worker change events work. The value of Targets doesn't trigger as "changed" until the field loses focus - if you click the up arrow to raise it to 2, it's still 1 until you click outside the field. So, if the user sets Targets to 2 and then immediately clicks Use Technique, the sheet hasn't had time to update the button, so it still fires off with just one target. Is there some easier way to do this that I'm overlooking? I feel like this has gotten way more complex than it ought to be.
1509554645

Edited 1509554806
I would do this using a sheet worker and updating the roll content for the technique. You would need an attribute for the technique (numTargets) that will hold the number of targets. Then the sheet worker would listen for a change on this variable and update the roll for that technique using a while loop and inject a @{target|Target #X|token_id} for each possible target. Edit: I see you already tried something like this and I didn't finish reading what you posted before responding. You could try changing the Targets field to a drop-down. That should force the sheet worker before the user clicks Use Technique. Or you could simply ask the user to click off of the Targets field before clicking Use Technique .
1509554966
Quinn
Pro
Sheet Author
Ooh, a dropdown is actually not a bad idea, since this is never gonna be a huge number. I'll give that a shot.