Difference between revisions of "Mod:Function/Roll20 object"
From Roll20 Wiki
(Created page with "Roll20 objects are a special kind of JavaScript object. They represent something in your campaign, such as a token on the tabletop or a character in the journal, and there is ...") |
(→get) |
||
Line 35: | Line 35: | ||
=== <code>get</code> === | === <code>get</code> === | ||
+ | {{function parameters | ||
+ | |parameter | ||
+ | |''(String)'' The name of the parameter to get. If you are getting the value of a read-only property (one which starts with an underscore, like <code>_id</code> or <code>_type</code>), the leading underscore is not required.}} | ||
+ | {{returns|The value of the specified property}} | ||
+ | ==== Examples ==== | ||
+ | <pre data-language="javascript">var character = getMyCharacter(), | ||
+ | strength = findObjs({ type: 'attribute', characterid: character.id, name: 'strength' })[0]; | ||
+ | |||
+ | log(strength.get('current'));</pre> | ||
+ | |||
+ | === <code>get</code> {{asynchronous}} === | ||
+ | This version of <code>get</code> will be automatically called if ''parameter'' is "notes", "gmnotes", or "bio" and the Roll20 object is a character or handout. | ||
+ | |||
+ | {{function parameters | ||
+ | |parameter | ||
+ | |''(String)'' The name of the parameter to get. If you are getting the value of a read-only property (one which starts with an underscore, like <code>_id</code> or <code>_type</code>), the leading underscore is not required. | ||
+ | |callback | ||
+ | |''(Function)'' A callback function which will receive the value of the property as a parameter.}} | ||
+ | {{returns}} | ||
+ | ==== Examples ==== | ||
+ | <pre data-language="javascript">var character = getMyCharacter(); | ||
+ | character.get('bio', function(text) { | ||
+ | log(text); | ||
+ | });</pre> | ||
+ | |||
=== <code>remove</code> === | === <code>remove</code> === | ||
=== <code>set</code> === | === <code>set</code> === | ||
[[Category:Docs]] | [[Category:Docs]] |
Revision as of 08:03, 29 July 2016
Roll20 objects are a special kind of JavaScript object. They represent something in your campaign, such as a token on the tabletop or a character in the journal, and there is some special consideration for using them. Extended Syntax Roll20 Objects is an API script which modifies how you can interact with Roll20 objects.
Contents |
Roll20 object fields
Property | Description |
---|---|
id
|
This property is shorthand for obj.get('id') .
|
id
This field is shorthand for obj.get('id')
. All Roll20 objects have a _id
property which uniquely identifies them within a campaign, but their properties are not directly accessible. Normally you have you call get
in order to get the value of a property, but because _id
is needed on such a frequent basis, this shim filed is provided for convenience.
Roll20 object functions
Return type | Function | Description |
---|---|---|
varies | get
|
Gets the value of a specified property. |
remove
|
Deletes the Roll20 object. | |
set
|
Sets one or more specified property values. |
get
Parameters
- parameter
- (String) The name of the parameter to get. If you are getting the value of a read-only property (one which starts with an underscore, like
_id
or_type
), the leading underscore is not required.
Returns
The value of the specified property
Examples
var character = getMyCharacter(), strength = findObjs({ type: 'attribute', characterid: character.id, name: 'strength' })[0]; log(strength.get('current'));
get
Asynchronous
This version of get
will be automatically called if parameter is "notes", "gmnotes", or "bio" and the Roll20 object is a character or handout.
Parameters
- parameter
- (String) The name of the parameter to get. If you are getting the value of a read-only property (one which starts with an underscore, like
_id
or_type
), the leading underscore is not required. - callback
- (Function) A callback function which will receive the value of the property as a parameter.
Returns
(Void)
Examples
var character = getMyCharacter(); character.get('bio', function(text) { log(text); });