Mass Rolling Macro (Help Needed)

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

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

Re: Mass Rolling Macro (Help Needed)

Post by aliasmask »

Irrlicht wrote:I thought Raktus wanted the input to pop up only once and apply the same settings for every token, doesn't that code make it appear for every token selected?
My input only shows up once outside of the loop. What may be happening in your testing is you have the macro set to "Apply to all tokens" which you don't want to do. That will essentially run it on each token, then loop through all the tokens making it run X squared times where X is the number of tokens selected.

User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Re: Mass Rolling Macro (Help Needed)

Post by Irrlicht »

Ah, alright, I hadn't tested it, but yes, I was mentally applying to selected tokens for habit.
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

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

Re: Mass Rolling Macro (Help Needed)

Post by aliasmask »

Irrlicht wrote:Ah, alright, I hadn't tested it, but yes, I was mentally applying to selected tokens for habit.
Something to note on that part though, if you do it my way anyone can run the macro on any tokens, even unowned tokens. More code will be needed if you want to limit the selected tokens to owned tokens, which is pretty easy. But in a friendly game, that probably isn't a high priority.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mass Rolling Macro (Help Needed)

Post by wolph42 »

edit: missed the fact that there was an entire page of discussion on teh next page, but ill leave this post anyway here.

I would do it slightly more efficient and more 'resilient':

Code: Select all

[H: selected = getSelectedNames("json")]
[h:assert(listCount(selected),"Make sure at least one token is selected",0)]

<!-- Set a variable outside of the foreach -->
[H:abort(input("attribute|Strength,Dexterity,Constitution|Select Attribute|LIST|VALUE=STRING"))]

[H: output = "[]"]
[H, foreach(tokenName,selected), if(isOwner(getPlayerName(), tokenName)), code: {
   [roll                = 1d20]
   [attributeBonus    = floor((number(getProperty(attribute, tokenName))-10)/2)]
   [result            = roll + attributeBonus]
   [output            = json.append(output,strformat("%{tokenName}: %{roll} + %{attributeBonus} = %{result}"))]
}]

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

Post Reply

Return to “Macros”