copyToken legacy
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.
- 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:
- The best methods in that case is to moveTokenFromMap() to the current map and then moveTokenToMap() back.
- 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.
- A final alternative is adding the 'lib:' prefix to the original, that way its properties are accessible throughout all maps
- 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.
- 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: <source lang="mtmacro" line> [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)] </syntaxhighlight>
Straightforward method: <source lang="mtmacro" line> [h:moveTokenFromMap("Hero", "Grasslands")] [h:setProperty("Strength", 3d6, "Hero")] [h:moveTokenToMap("Hero", "Grasslands")] [h:copyToken("Hero", 1, "Grasslands")] </syntaxhighlight>
Fancy method that leave the original token unchanged <source lang="mtmacro" line> [h:moveTokenFromMap("Hero", "Grasslands")] [h:origId = findToken("Hero")] [h:origCopyId = copyToken("Hero", 1, "", "{name: 'Hero'}")] [h:setProperty("Strength", 3d6, origId)] [h:copyToken(origId, 1)] [h:removeToken(origId)] [h:moveTokenToMap(origCopyId, "Grasslands")]</syntaxhighlight>