Copy and Place Token

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
Puddlefist
Kobold
Posts: 9
Joined: Thu Mar 31, 2022 11:21 pm

Copy and Place Token

Post by Puddlefist »

I have been able to create a macro that copies a token and can place it x number of spaces.

However I am looking to copy a token and place it in the middle of my current view. Any thoughts?

User avatar
Torlan
Kobold
Posts: 15
Joined: Fri Jan 07, 2022 8:12 am

Re: Copy and Place Token

Post by Torlan »

Never tried, but i think the Wiki: goto() function might be of help.
Roses are grey, violets are grey...I'm dead and colorblind!

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Copy and Place Token

Post by aliasmask »

getViewCenter may be what you want.

Puddlefist
Kobold
Posts: 9
Joined: Thu Mar 31, 2022 11:21 pm

Re: Copy and Place Token

Post by Puddlefist »

Alias, you have me on the right track...

Code: Select all

[H: id = copyToken("Hero")]       <!-- copies token and gets id -->
[h:selectTokens(id)]              <!-- selects the new token -->
[h:switchToken(getSelected())]    <!-- impersonates the token so it can be moved -->
[h: setVisible(0, id)]            <!-- hides token from players -->
[h: location = getViewCenter()]   <!-- gets coordinates for center of the display -->
[h: moveToken(centerX, centerY)]  <!-- moves the token to center of display -->
getViewCenter gives me: centerX=1754,centerY=1159; and when I run the above, it opens dialogue boxes asking for values for centerX and centerY.

How do I get the coordinates out of getViewCenter and into moveToken?

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Copy and Place Token

Post by aliasmask »

Code: Select all

[H: json.toVars(getViewCenter(1, "json"))]
json.toVars is a fancy way of converting a json set of values in to local variables.

Puddlefist
Kobold
Posts: 9
Joined: Thu Mar 31, 2022 11:21 pm

Re: Copy and Place Token

Post by Puddlefist »

This works so well. Thank you so much!

Final macro:

Code: Select all

[h: id = copyToken("Hero")]                 <!-- copies token and gets id -->
[h:selectTokens(id)]                        <!-- selects the new token -->
[h:switchToken(getSelected())]              <!-- impersonates the token so it can be moved -->
[h: setVisible(0, id)]                      <!-- hides token from players -->
[h: location = getViewCenter()]             <!-- gets coordinates for center of the display -->
[H: json.toVars(getViewCenter(1, "json"))]  <!-- converts coordinates to variables -->
[h: moveToken(centerX, centerY)]            <!-- moves the token to center of display -->

Post Reply

Return to “Macros”