setOwner: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
Line 19: | Line 19: | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[h: setOwner("Frank")] | [h: setOwner("Frank")] | ||
</source> | |||
To change the [[Owners|owners]] of the [[Current Token]] to a list of three players use: | |||
<source lang="mtmacro" line> | |||
[h: setOwner("['Peter', 'Paul', 'Mary']")] | |||
</source> | |||
To remove all [[Owners|owners]] of the [[Current Token]] use: | |||
<source lang="mtmacro" line> | |||
[h: setOwner("")] | |||
</source> | |||
or: | |||
<source lang="mtmacro" line> | |||
[h: setOwner("[]")] | |||
</source> | </source> | ||
Revision as of 04:20, 31 December 2010
setOwner() Function
• Introduced in version 1.3b48?
Changes the owners of a token (default is the Current Token) when given a String owner name or JSON Array of owner names. All other owners are removed.
Usage
setOwner(ownerName, id)
setOwner(ownerNames, id)
Parameters
ownerName
- The player name to set the ownership on the token. Ownership is not constrained to the client names currently connected, but only currently connected clients appear in the Token Editor Dialog. This parameter is a String. An empty string here is treated as an empty JSON array (see next parameter).ownerNames
- The player names to set the ownership on the token. Ownership is not constrained to the client names currently connected, but only currently connected clients appear in the Token Editor Dialog. This parameter is a JSON Array.id
- The tokenid
of the token which has its owners changed, defaults to the Current Token.Note: This parameter can only be used in a Trusted Macro.
Examples
To change the owners of the Current Token to a single user use:
[h: setOwner("Frank")]
To change the owners of the Current Token to a list of three players use:
[h: setOwner("['Peter', 'Paul', 'Mary']")]
To remove all owners of the Current Token use:
[h: setOwner("")]
or:
[h: setOwner("[]")]
To display the current owners of the Current Token as checkboxes, then accept the user's changes to apply back onto the token, use the following. Note that this example does not provide for adding owners to the list, only removing them. (Adding owners would require the use of getAllPlayerNames() and would make this example even more complex.)
[h: names = getOwners("json")]
[h: input = "tab0 | OwnerList || TAB"]
[h: count = 0]
[h, foreach(name, names), code: {
[input = input + strformat(" ## ckb_%{count}|1|%{name}|CHECK")]
[count = count+1]
} ]
[h: cancel = input(input)]
[h: abort(cancel)]
[h: newOwners = "[]"]
[h, for(x,0,count):
newOwners = if(eval("ckb_"+x)==0, newOwners, json.append(newOwners, json.get(names, x))) ]
[h: setOwner(newOwners)]
See Also
Version Changes
- 1.3b51 - Added
id
parameter option.