One Dialog - Apply To Many Selected Tokens?

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
adventuremagic123
Cave Troll
Posts: 43
Joined: Sun Jan 06, 2019 12:29 pm

One Dialog - Apply To Many Selected Tokens?

Post by adventuremagic123 »

Can someone tell me how to write a macro with a dialog (I currently use "input"), where I do the following:

1. Select tokens.
2. Click the button to invoke the macro.
3. Dialog pops up, I enter data, and click OK.
4. Update the selected tokens.

Problem: What is the best practice to use to stop the macro from being invoked for each selected token?

User avatar
aliasmask
Deity
Posts: 8667
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: One Dialog - Apply To Many Selected Tokens?

Post by aliasmask »

Writing an HTML form is its own issue and wolph42 has a tutorial in his signature, but the macro you run will have Apply to Selected unchecked. Then you'll use getSelected() in your code to loop through the tokens to make the changes. This is the way to have the code run once rather than on each token.

I personally would probably still use the input() function for data entry because its so easy, but if you want a dialog to stick around then the html form is the way to go.

The one real issue you may have is permissions. If this is a macro used by players then they may be able to update tokens they're not supposed to update. User isOwner() or isOwnedByAll() is one way to filter out tokens not owned by the player. Or you can limit the whole macro to GM only with isGM().

adventuremagic123
Cave Troll
Posts: 43
Joined: Sun Jan 06, 2019 12:29 pm

Re: One Dialog - Apply To Many Selected Tokens?

Post by adventuremagic123 »

aliasmask wrote:
Wed May 15, 2019 6:36 am
Writing an HTML form is its own issue and wolph42 has a tutorial in his signature, but the macro you run will have Apply to Selected unchecked. Then you'll use getSelected() in your code to loop through the tokens to make the changes. This is the way to have the code run once rather than on each token.

I personally would probably still use the input() function for data entry because its so easy, but if you want a dialog to stick around then the html form is the way to go.

The one real issue you may have is permissions. If this is a macro used by players then they may be able to update tokens they're not supposed to update. User isOwner() or isOwnedByAll() is one way to filter out tokens not owned by the player. Or you can limit the whole macro to GM only with isGM().
Thank you very much. Yes, I use input for my dialogs. Maybe, I'll try an HTML version someday when I'm further along. Right now, function is more important than beauty.


Post Reply

Return to “Macros”