copyToken: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Correct version.)
(Updated details and examples)
Line 1: Line 1:
{{stub}}
 
{{MacroFunction
{{MacroFunction
|name=copyToken
|name=copyToken
|trusted=true
|trusted=true
|version=1.3b51
|version=1.3b51
|description
|description=Creates one or more copies of a [[Token]]. This function is used to copy [[Token]]s into the current map, the [[Token]]s you are making
Used to copy a token into the current map. You can use it to copy a token from another map into the current map.
copies of can be reside on any map. You can not make any modifications to the newly created [[Token]]s in the macro that creates them.
As of b54 there is a new parameter that allows you to make some changes to the new tokens.
 


|usage=
|usage=
<source lang="mtmacro" line>
<source lang="mtmacro" line>
copyToken([i]id)
copyToken(id)
</source>
</source>
<source lang="mtmacro" line>
<source lang="mtmacro" line>
copyToken([i]id, numCopies)
copyToken(id, numCopies)
</source>
</source>
<source lang="mtmacro" line>
<source lang="mtmacro" line>
copyToken([i]id, numCopies, fromMap)
copyToken(id, numCopies, fromMap)
</source>
</source>
<source lang="mtmacro" line>
copyToken(id, numCopies, fromMap, updates)
</source>
'''Parameters'''
'''Parameters'''
{{param|id|The id of the token to copy.}}
{{param|id|The id of the token to copy.}}
{{param|numCopies|The number of copies to create, defaults to {{code|1}}}}
{{param|numCopies|The number of copies to create, defaults to {{code|1}} }}
{{param|fromMap|The name of the map to copy from, defaults to the current map.}}
{{param|fromMap|The name of the map to copy from, defaults to the current map.}}
{{param|updates| a [[JSON Object]] that contains updates to be made to the copied [[Token]]s.}}
You can use an empty string ("") for {{code|fromMap}} for the current map as of b54.
The return type of this function is determined by the number of copies that you are making. If you are only creating a single
copy of the token then a string containing the [[Token]]s id, if you are making more than one copy then a [[JSON Array]]
containing the [[Token]] ids of all the newly created [[Token]]s is returned.
'''Updates parameter'''
{{code|updates}} is a [[JSON Object]] that can contain one or more of the following fields.
* name - The name of the new [[Token]].
* label - The label for the new [[Token]].
* gmName - The GM name for the new [[Token]].
* layer - The layer for the new [[Token]].
* x - The X Co-ordinate for the new [[Token]].
* y - The Y Co-ordinate for the new [[Token]].
* useDistance - {{code|true}} or {{code|false}}, determines if the "Distance Per Cell" measurement for the map is used for the x,y Co-ordinates.
* facing - Sets the facing for the [[Token]]. If the [[Token]] is on the background or object layer this sets the rotation.
* size - Sets the size of the [[Token]].
The values for all of these fields are evaluated so all text within {{code|{} }} or {{code|[]}} goes through the standard macro processing.
When the name is not changed using the {{code|updates}} parameter the new name for the token follows the naming method for cut and paste.
This function can copy [[Token]]s in the token or hidden layer, objects, or background, if you do not override the destination using the
{{code|layer}} field of {{code|updates}} then the new copies are made in the same layer as the source. Likewise if {{code|x}} and {{code|y}}
are not specified then these locations are the same as the source.
|example=
Make a single copy of the Hero from the current map.
<source lang="mtmacro" line>
[h:copyToken("Hero")]
</source>
Make a single copy of the Hero from another map.
<source lang="mtmacro" line>
[h:copyToken("Hero", 1, "Green Room")]
</source>
Or if you are playing paranoia and want to create six clones.
<source lang="mtmacro" line>
[h:copyToken("Hero", 6, "Clone Vat")]
</source>
But as a PC the new tokens don't get new names so we could give each of them a new name in b54+ using the following.
<source lang="mtmacro" line>
[h: cloneNo = 0]
[h: updates = "{
                name:'Hero Clone - [r: cloneNo = cloneNo + 1]'
              }"
]
[h: cloneNo = 0]
[h:copyToken("Hero", 6, "Clone Vat", updates)]
</source>
This will copy all our clones to the current map but they are all on top of each other, to line them up
<source lang="mtmacro" line>
[h: cloneNo = 0]
[h: x = 0]
[h: updates = "{
                name:'Hero Clone - [r: cloneNo = cloneNo + 1]',
                x:'[r: x = x + 2]',
                y:0
              }"
]
[h: cloneNo = 0]
[h:copyToken("Hero", 6, "Clone Vat", updates)]
</source>
Or combining rotation
<source lang="mtmacro" line>
[h: cloneNo = 0]
[h: x = 0]
[h: facing = 0]
[h: updates = "{
                name:'Hero Clone - [r: cloneNo = cloneNo + 1]',
                x:'[r: x = x + 2]',
                y:0,
                facing: '[r: facing = facing + 40]'
              }"
]
[h: cloneNo = 0]
[h:copyToken("Hero", 6, "Clone Vat", updates)]
</source>


If numCopies is 1 then the token id of the newly create token is the return value of the function,
And now we have tumbling clones
If numCopies is greater than 1 then the return is a JSON Array with all of the newly created token ids.


The naming of the tokens follows the cut/paste token method.
[[Image:TumblingClones.jpeg]]


Although it says token it can be used for objects etc.
The source token was configured as a Top Down token for this effect, otherwise the {{code|facing}} setting would produce a facing arrow.
Tokens are copied into the same layer as the original token, also with the same x,y co-ordinates, but you get the token ids as a return value so its easy to use other functions to change these.
}}
}}
[[Category:Token Function]]
[[Category:Token Function]]

Revision as of 08:57, 27 March 2009


copyToken() Function

 Note: This function can only be used in a Trusted Macro

Introduced in version 1.3b51
Creates one or more copies of a Token. This function is used to copy Tokens into the current map, the Tokens you are making

copies of can be reside on any map. You can not make any modifications to the newly created Tokens in the macro that creates them.

As of b54 there is a new parameter that allows you to make some changes to the new tokens.

Usage

copyToken(id)
copyToken(id, numCopies)
copyToken(id, numCopies, fromMap)
copyToken(id, numCopies, fromMap, updates)


Parameters

  • id - The id of the token to copy.
  • numCopies - The number of copies to create, defaults to 1
  • fromMap - The name of the map to copy from, defaults to the current map.
  • updates - a JSON Object that contains updates to be made to the copied Tokens.

You can use an empty string ("") for fromMap for the current map as of b54.


The return type of this function is determined by the number of copies that you are making. If you are only creating a single copy of the token then a string containing the Tokens id, if you are making more than one copy then a JSON Array containing the Token ids of all the newly created Tokens is returned.


Updates parameter

updates is a JSON Object that can contain one or more of the following fields.

  • name - The name of the new Token.
  • label - The label for the new Token.
  • gmName - The GM name for the new Token.
  • layer - The layer for the new Token.
  • x - The X Co-ordinate for the new Token.
  • y - The Y Co-ordinate for the new Token.
  • useDistance - true or false, determines if the "Distance Per Cell" measurement for the map is used for the x,y Co-ordinates.
  • facing - Sets the facing for the Token. If the Token is on the background or object layer this sets the rotation.
  • size - Sets the size of the Token.

The values for all of these fields are evaluated so all text within {} or [] goes through the standard macro processing.


When the name is not changed using the updates parameter the new name for the token follows the naming method for cut and paste. This function can copy Tokens in the token or hidden layer, objects, or background, if you do not override the destination using the layer field of updates then the new copies are made in the same layer as the source. Likewise if x and y are not specified then these locations are the same as the source.

Example

Make a single copy of the Hero from the current map.
[h:copyToken("Hero")]

Make a single copy of the Hero from another map.

[h:copyToken("Hero", 1, "Green Room")]

Or if you are playing paranoia and want to create six clones.

[h:copyToken("Hero", 6, "Clone Vat")]

But as a PC the new tokens don't get new names so we could give each of them a new name in b54+ using the following.

[h: cloneNo = 0]
[h: updates = "{ 
                 name:'Hero Clone - [r: cloneNo = cloneNo + 1]'
               }"
]
[h: cloneNo = 0]
[h:copyToken("Hero", 6, "Clone Vat", updates)]

This will copy all our clones to the current map but they are all on top of each other, to line them up

[h: cloneNo = 0]
[h: x = 0]
[h: updates = "{ 
                 name:'Hero Clone - [r: cloneNo = cloneNo + 1]',
                 x:'[r: x = x + 2]',
                 y:0
               }"
]
[h: cloneNo = 0]
[h:copyToken("Hero", 6, "Clone Vat", updates)]

Or combining rotation

[h: cloneNo = 0]
[h: x = 0]
[h: facing = 0]
[h: updates = "{ 
                 name:'Hero Clone - [r: cloneNo = cloneNo + 1]',
                 x:'[r: x = x + 2]',
                 y:0,
                 facing: '[r: facing = facing + 40]'
               }"
]
[h: cloneNo = 0]
[h:copyToken("Hero", 6, "Clone Vat", updates)]

And now we have tumbling clones

The source token was configured as a Top Down token for this effect, otherwise the facing setting would produce a facing arrow.