setOwner: Difference between revisions
Jump to navigation
Jump to search
(setOwner) |
No edit summary |
||
(15 intermediate revisions by 6 users not shown) | |||
Line 3: | Line 3: | ||
|version=1.3b48? | |version=1.3b48? | ||
|description= | |description= | ||
Changes the owners of a token (default is the [[Current Token]]) when given a [[ | 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= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
setOwner(ownerName) | setOwner(ownerName) | ||
setOwner(ownerName, tokenRef) | |||
setOwner(ownerName, tokenRef, mapRef) | |||
setOwner(ownerNames, | setOwner(ownerNames) | ||
</ | setOwner(ownerNames, tokenRef) | ||
setOwner(ownerNames, tokenRef, mapRef) | |||
</syntaxhighlight> | |||
'''Parameters''' | '''Parameters''' | ||
{{param|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 [[ | {{param|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). }} | ||
{{param|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]]. }} | {{param|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]]. }} | ||
{{param| | {{param|tokenRef|Either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token, defaults to the [[Current Token]]. {{TrustedParameter}} }} | ||
{{param|mapRef|The Name or ID of the map to find the token. Defaults to the current map.}} | |||
{{Note|Token IDs are unique, but Token Names can be duplicated. Using Token Name when more than one token has the same name can produce unexpected results.}} | |||
|examples= | |examples= | ||
To change the [[ | To change the [[Introduction_to_Tokens#Ownership|owners]] of the [[Current Token]] to a single user use: | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: setOwner("Frank")] | [h: setOwner("Frank")] | ||
</ | </syntaxhighlight> | ||
To change the [[Introduction_to_Tokens#Ownership|owners]] of the [[Current Token]] to a list of three players use: | |||
<syntaxhighlight lang="mtmacro" line> | |||
[h: setOwner("['Peter', 'Paul', 'Mary']")] | |||
</syntaxhighlight> | |||
or: | |||
<syntaxhighlight lang="mtmacro" line> | |||
[h: list = json.append("[]", "Peter", "Paul", "Mary")] | |||
[h: setOwner(list)] | |||
</syntaxhighlight> | |||
To make all current players [[Introduction_to_Tokens#Ownership|owners]] of the [[Current Token]] use: | |||
<syntaxhighlight lang="mtmacro" line> | |||
[h: setOwner(getAllPlayerNames("json"))] | |||
</syntaxhighlight> | |||
To remove all [[Introduction_to_Tokens#Ownership|owners]] of the [[Current Token]] use: | |||
<syntaxhighlight lang="mtmacro" line> | |||
[h: setOwner("")] | |||
</syntaxhighlight> | |||
or: | |||
<syntaxhighlight lang="mtmacro" line> | |||
[h: setOwner("[]")] | |||
</syntaxhighlight> | |||
To display the current [[ | To display the current [[Introduction_to_Tokens#Ownership|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 {{func|getAllPlayerNames}} and would make this example even more complex.) | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: names = getOwners("json")] | [h: names = getOwners("json")] | ||
[h: input = "tab0 | OwnerList || TAB"] | [h: input = "tab0 | OwnerList || TAB"] | ||
Line 38: | Line 67: | ||
newOwners = if(eval("ckb_"+x)==0, newOwners, json.append(newOwners, json.get(names, x))) ] | newOwners = if(eval("ckb_"+x)==0, newOwners, json.append(newOwners, json.get(names, x))) ] | ||
[h: setOwner(newOwners)] | [h: setOwner(newOwners)] | ||
</ | </syntaxhighlight> | ||
|also= | |also= | ||
Line 47: | Line 76: | ||
|changes= | |changes= | ||
{{change|1.3b51|Added {{code|id}} parameter option.}} | {{change|1.3b51|Added {{code|id}} parameter option.}} | ||
{{change|1.5.4|Added {{code|mapname}} parameter option.}} | |||
}} | }} | ||
[[Category:Token Function]] | [[Category:Token Function]] |
Latest revision as of 23:59, 10 May 2024
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)
setOwner(ownerName, tokenRef)
setOwner(ownerName, tokenRef, mapRef)
setOwner(ownerNames)
setOwner(ownerNames, tokenRef)
setOwner(ownerNames, tokenRef, mapRef)
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.tokenRef
- Either the tokenid
or Token Name of the token, defaults to the Current Token.Note: This parameter can only be used in a Trusted Macro.
mapRef
- The Name or ID of the map to find the token. Defaults to the current map.
Token IDs are unique, but Token Names can be duplicated. Using Token Name when more than one token has the same name can produce unexpected results.
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']")]
or:
[h: list = json.append("[]", "Peter", "Paul", "Mary")]
[h: setOwner(list)]
To make all current players owners of the Current Token use:
[h: setOwner(getAllPlayerNames("json"))]
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. - 1.5.4 - Added
mapname
parameter option.