Global variables... Or a way to use the same input on multiple 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
Shadow Wizard
Giant
Posts: 182
Joined: Mon Apr 11, 2011 8:11 pm

Global variables... Or a way to use the same input on multiple tokens.

Post by Shadow Wizard »

It happens quite often I select a large group of tokens, and run a very simple macro. Perhaps this one:
[h: setProperty("baseHpFormula", swgetforuma)]
And it asks me for input for every macro. But I have selected 10 macros, and the input is the same for every one of them.. That's why I selected 10 macros.
To my way of thinking, I would just set swgetforuma to a global variable, so it would ask once, and then not ask again for each token selected..
Of course, this will not work unless I can UNSET it after every group use..
Basically, what I want is to do is select a bunch of tokens that all have the same macro, use that macro, and it ask me for input once, and then have it set the property on every token selected.
Possible? Other ways to do this?

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

Re: Global variables... Or a way to use the same input on multiple tokens.

Post by aliasmask »

yes, uncheck "Apply to Selected" because that will run the macro separately on each token. Now you create your own loop in the macro code, the process will be something like this

Code: Select all

[H: tokenIds = getSelected()]
<!-- do stuff like get user input -->

[H, foreach(id,tokenIds), code: {
  [H: switchToken(id)]
  <!-- do the stuff that applies to all the tokens -->
}]  
You may want to filter the tokenIds because it will apply to owned and unowned tokens selected, but sometimes that's okay.

Shadow Wizard
Giant
Posts: 182
Joined: Mon Apr 11, 2011 8:11 pm

Re: Global variables... Or a way to use the same input on multiple tokens.

Post by Shadow Wizard »

So that means they would need to be global or GM macros rather then token macros I am assuming?

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

Re: Global variables... Or a way to use the same input on multiple tokens.

Post by aliasmask »

Shadow Wizard wrote:
Sun Jul 10, 2022 9:32 am
So that means they would need to be global or GM macros rather then token macros I am assuming?
Correct, putting the macro in the Campaign Window which would reference a macro on a lib token is the typical way.

Post Reply

Return to “Macros”