copyToken legacy

From RPTools Wiki
(Redirected from CopyToken legacy)
Jump to navigation Jump to search

Guide to Modifying Token Copies for legacy MapTool versions

For MapTool versions prior to 1.5.7

You can not make any modifications to the newly created Tokens in the macro that creates them. Any changes made to the newly created token are reverted as soon as the macro ends! As of b54 there is a new parameter (update) that allows you to make some changes to the new tokens.

How to make additional changes to the newly created token

As said, ANY changes made to the new token will be reverted as soon as the macro ends. However there are a couple of methods to do it anyway.

  1. The most reliable and straightforward method is to change the ORIGINAL token first and then copy it. You *can* revert the changes to the original after the copyToken. However if the original token is not on the same map then you can't immediately change the original. To solve that here some methods:
    1. The best methods in that case is to moveTokenFromMap() to the current map and then moveTokenToMap() back.
    2. You could also use setCurrentMap()) to go to the 'original' map, change the token and switch back, that however will result in a minor flicker on screen.
    3. A final alternative is adding the 'lib:' prefix to the original, that way its properties are accessible throughout all maps
  2. The simplest method is by creating an interrupt in the macro after the copies have been made. This is simply done with the use of input(). This however will result in a pop-up on screen which you have to click away so the macro can continue with the update.
  3. Another (not always working method) is to make changes to the created tokens done by a second 'deferred' macro that is called after the copies have been created. Look for execLink for calling a macro deferred.

Examples of updates after copy

Simplest method:

[h:id=copyToken("Hero")]
[h:input("junk|This interruption is required to create the new token. Click ok to continue.|Message |LABEL")]
[h:setProperty("Strength", 3d6,id)]

Straightforward method:

[h:moveTokenFromMap("Hero", "Grasslands")]
[h:setProperty("Strength", 3d6, "Hero")]
[h:moveTokenToMap("Hero", "Grasslands")]
[h:copyToken("Hero", 1, "Grasslands")]

Fancy method that leave the original token unchanged

[h:moveTokenFromMap("Hero", "Grasslands")]
<!-- swap from name to token id as tokens with the same name will soon exist -->
[h:origId = findToken("Hero")]
<!-- copy original with same name -->
[h:origCopyId = copyToken("Hero", 1, "", "{name: 'Hero'}")]
<!-- update original with new properties -->
[h:setProperty("Strength", 3d6, origId)]
<!-- copy and then delete original -->
[h:copyToken(origId, 1)]
[h:removeToken(origId)]
<!-- move the copy from BEFORE the changes back to the original map -->
[h:moveTokenToMap(origCopyId, "Grasslands")]