Macro

Macro

The Macro entity which implements a triggered chat or script expression which can be quickly activated by the user. All users have permission to create and use chat-based Macros, but users must be given special permission to use script-based macros.

Constructor

new Macro()

Source:
See:
  • Macros The Collection of Macro entities
  • MacroConfig The Macro Configuration sheet
  • Hotbar The Hotbar interface application

Extends

Members

(static) config

Source:

apps :Object.<Application>

Source:
Inherited From:
See:

A collection of Application instances which should be re-rendered whenever this Entity experiences an update to its data. The keys of this object are the application ids and the values are Application instances. Each Application in this object will have its render method called by @{link Entity#render}.

Type:

compendium :Compendium|null

Source:
Inherited From:

The Entity may optionally belong to a parent Compendium pack. If so this attribute will contain a reference to that Compendium object. Otherwise null.

Type:

data :Object

Source:
Inherited From:

The original source data for the object provided at initialization.

Type:
  • Object

folder :Folder|null

Source:
Inherited From:

Return a reference to the Folder which this Entity belongs to, if any.

Type:
Example

Entities may belong to Folders

let folder = game.folders.entities[0];
let actor = await Actor.create({name: "New Actor", folder: folder.id});
console.log(actor.data.folder); // folder.id;
console.log(actor.folder); // folder;

id :string

Source:
Inherited From:

A convenience accessor for the _id attribute of the Entity data object.

Type:
  • string

limited :boolean

Source:
Inherited From:

A boolean indicator for whether the current game user has ONLY limited visibility for this Entity. Note that a GM user's perspective of an Entity is never limited.

Type:
  • boolean

name :string

Source:
Inherited From:

A convenience accessor for the name attribute of the Entity data object

Type:
  • string

options :Object

Source:
Inherited From:

The options object that was used to configure the Entity upon initialization.

Type:
  • Object

owner :boolean

Source:
Inherited From:

A boolean indicator for whether or not the current game User has ownership rights for this Entity. This property has a setter which allows for ownership rights to be temporarily overridden on a per-instance basis.

Type:
  • boolean

permission :Number

Source:
Inherited From:

Return the permission level that the current game User has over this Entity. See the CONST.ENTITY_PERMISSIONS object for an enumeration of these levels.

Type:
Example
game.user.id; // "dkasjkkj23kjf"
entity.data.permission; // {default: 1, "dkasjkkj23kjf": 2};
entity.permission; // 2

sheet :BaseEntitySheet

Source:
Inherited From:

A property which gets or creates a singleton instance of the sheet class used to render and edit data for this particular entity type.

Type:
Example

A subclass of the Actor entity

let actor = game.entities.actors[0];
actor.sheet; // ActorSheet

uuid :string

Source:
Inherited From:

A Universally Unique Identifier (uuid) for this Entity instance

Type:
  • string

visible :boolean

Source:
Inherited From:

A boolean indicator for whether or not the current game User has at least limited visibility for this Entity.

Type:
  • boolean

Methods

(async) clone(createData, options) → {Promise.<Entity>}

Source:
Inherited From:

Clone an Entity, creating a new Entity using the current data as well as provided creation overrides.

Parameters:
Name Type Description
createData Object

Additional data which overrides current Entity data at the time of creation

options Object

Additional creation options passed to the Entity.create method

Returns:

A Promise which resolves to the created clone Entity

Type
Promise.<Entity>

(async) createEmbeddedEntity(embeddedName, createData, options) → {Promise}

Source:
Inherited From:

Create one EmbeddedEntity within this parent Entity. Dispatch the creation request to the server for handling. The result will be acknowledged to this client, and broadcast to other connected clients.

Parameters:
Name Type Description
embeddedName string

The name of the Embedded Entity class to create

createData Object

An object of initial data from which to create the Embedded Entity

options Object

Additional creation options which modify the request

Returns:

A Promise which resolves to this Entity once the creation request is successful

Type
Promise

(async) createManyEmbeddedEntities(embeddedName, createData, options) → {Promise}

Source:
Inherited From:

Create multiple Embedded Entities within this parent Entity using an Array of creation data. Dispatch the update request to the server for handling. The result will be acknowledged to this client, and broadcast to other connected clients.

Parameters:
Name Type Description
embeddedName string

The name of the Embedded Entity class to update

createData Array

An Array of initial data objects from which to create the Embedded Entities.

options Object

Additional update options which modify the request

Returns:

A Promise which resolves to this Entity once the creation request is successful

Type
Promise

(async) delete(options) → {Promise}

Source:
Inherited From:

Delete the entity, removing it from its collection and deleting its data record

Example
const deleted = await entity.delete();
Parameters:
Name Type Description
options Object

Additional options which customize the deletion workflow

Returns:

A Promise which resolves to the ID of the deleted Entity once handled by the server

Type
Promise

(async) deleteEmbeddedEntity(embeddedName, childId, options) → {Promise}

Source:
Inherited From:

Delete one EmbeddedEntity within this parent Entity. Dispatch the deletion request to the server for handling. The result will be acknowledged to this client, and broadcast to other connected clients.

Parameters:
Name Type Description
embeddedName string

The name of the Embedded Entity class to delete

childId string

The id of the existing Embedded Entity child to delete

options Object

Additional deletion options which modify the request

Returns:

A Promise which resolves to this Entity once the deletion request is successful

Type
Promise

(async) deleteManyEmbeddedEntities(embeddedName, deleteIds, options) → {Promise}

Source:
Inherited From:

Delete multiple Embedded Entities within this parent Entity by an Array of child ids. Dispatch the update request to the server for handling. The result will be acknowledged to this client, and broadcast to other connected clients.

Parameters:
Name Type Description
embeddedName string

The name of the Embedded Entity class to update

deleteIds Array

An Array of Embedded Entity ids to delete from the parent Entity

options Object

Additional update options which modify the request

Returns:

A Promise which resolves to this Entity once the update request is successful

Type
Promise

execute() → {Promise}

Source:

Execute the Macro command

Returns:
Type
Promise

exportToJSON()

Source:
Inherited From:

Export entity data to a JSON file which can be saved by the client and later imported into a different session

getEmbeddedCollection(embeddedName) → {Array}

Source:
Inherited From:

Obtain a reference to the Array of source data within the data object for a certain Embedded Entity name

Parameters:
Name Type Description
embeddedName string

The name of the Embedded Entity type

Returns:

The Array of source data where Embedded Entities of this type are stored

Type
Array

getEmbeddedEntity(embeddedName, id, strict) → {Object|null}

Source:
Inherited From:

Get an Embedded Entity by it's id from a named collection in the parent Entity.

Parameters:
Name Type Description
embeddedName string

The name of the Embedded Entity type to retrieve

id string

The numeric ID of the child to retrieve

strict boolean

Throw an Error if the requested id does not exist, otherwise return null. Default false.

Returns:

Retrieved data for the requested child, or null

Type
Object | null

getFlag(scope, key) → {*}

Source:
Inherited From:

Get the value of a "flag" for this Entity See the setFlag method for more details on flags

Parameters:
Name Type Description
scope String

The flag scope which namespaces the key

key String

The flag key

Returns:

The flag value

Type
*

hasPerm(user, permission, exact) → {boolean}

Source:
Inherited From:

Test whether a provided User a specific permission level (or greater) over the Entity instance

Example

Test whether a specific user has a certain permission

// These two are equivalent
entity.hasPerm(game.user, "OWNER");
entity.owner;
// These two are also equivalent
entity.hasPerm(game.user, "LIMITED", true);
entity.limited;
Parameters:
Name Type Default Description
user User

The user to test for permission

permission string | number

The permission level or level name to test

exact boolean false

Tests for an exact permission level match, by default this method tests for an equal or greater permission level.

Returns:

Whether or not the user has the permission for this Entity.

Type
boolean

(async) importFromJSON(json) → {Promise.<Entity>}

Source:
Inherited From:

Import data and update this entity

Parameters:
Name Type Description
json String

JSON data string

Returns:

The updated Entity

Type
Promise.<Entity>

(async) importFromJSONDialog() → {Promise.<void>}

Source:
Inherited From:

Render an import dialog for updating the data related to this Entity through an exported JSON file

Returns:
Type
Promise.<void>

initialize()

Source:
Inherited From:

Initialize data structure for the Entity. First initialize any Embedded Entities and prepare their data. Next prepare data for the Entity itself, which may depend on Embedded Entities.

prepareData()

Source:
Inherited From:

Prepare data for the Entity whenever the instance is first created or later updated. This method can be used to derive any internal attributes which are computed in a formulaic manner. For example, in a d20 system - computing an ability modifier based on the value of that ability score.

prepareEmbeddedEntities()

Source:
Inherited From:

Prepare Embedded Entities which exist within this parent Entity. For example, in the case of an Actor, this method is responsible for preparing the Owned Items the Actor contains.

removeEmbeddedEntity(embeddedName, id) → {Object|null}

Source:
Inherited From:

Remove an Embedded Entity from the parent Entity data by it's id.

Parameters:
Name Type Description
embeddedName string

The name of the Embedded Entity type to retrieve

id number

The numeric ID of the child to retrieve

Returns:

The embedded entity data that was removed

Type
Object | null

render(…args)

Source:
Inherited From:

Render all of the Application instances which are connected to this Entity by calling their respective Application#render methods.

Parameters:
Name Type Attributes Description
args * <repeatable>

Variable arguments which are forwarded to each Application's render call

(async) setFlag(scope, key, value) → {Promise.<Entity>}

Source:
Inherited From:

Assign a "flag" to this Entity. Flags represent key-value type data which can be used to store flexible or arbitrary data required by either the core software, game systems, or user-created modules.

Each flag should be set using a scope which provides a namespace for the flag to help prevent collisions.

Flags set by the core software use the "core" scope. Flags set by game systems or modules should use the canonical name attribute for the module Flags set by an individual world should "world" as the scope.

Flag values can assume almost any data type. Setting a flag value to null will delete that flag.

Parameters:
Name Type Description
scope String

The flag scope which namespaces the key

key String

The flag key

value *

The flag value

Returns:

A Promise resolving to the updated Entity

Type
Promise.<Entity>

(async) sortRelative()

Source:
Inherited From:

Sort this Entity relative a target by providing the target, an Array of siblings and other options. If the Entity has an rendered sheet, record the sort change as part of a form submission See SortingHelper.performIntegerSort for more details

toJSON() → {Object}

Source:
Inherited From:

Serializing an Entity should simply serialize it's inner data, not the entire instance

Returns:
Type
Object

(async) unsetFlag(scope, key) → {Promise}

Source:
Inherited From:

Remove a flag assigned to the Entity

Parameters:
Name Type Description
scope string

The flag scope which namespaces the key

key string

The flag key

Returns:

A Promise resolving to the updated Entity

Type
Promise

(async) update(data, options) → {Promise}

Source:
Inherited From:

Update the current entity using new data This new data is typically provided from the server through the 'update' socket Alternatively, the update may originate locally, in which case it can be pushed back to the server

Example
const updateData = {name: "New Name"};
const updated = await entity.update(updateData);
Parameters:
Name Type Description
data Object

The data with which to update the entity

options Object

Additional options which customize the update workflow

Properties
Name Type Description
diff Boolean

Diff the provided data against existing entity data, only submitting the difference to the server. Default is true.

Returns:

A Promise which resolves to the updated Entity

Type
Promise

(async) updateEmbeddedEntity(embeddedName, updateData, options) → {Promise}

Source:
Inherited From:

Update one EmbeddedEntity within this parent Entity using incremental data. Dispatch the update request to the server for handling. The result will be acknowledged to this client, and broadcast to other connected clients.

Parameters:
Name Type Description
embeddedName string

The name of the Embedded Entity class to update

updateData Object

An object of incremental data from which to update the Embedded Entity

options Object

Additional update options which modify the request

Returns:

A Promise which resolves to this Entity once the update request is successful

Type
Promise

(async) updateManyEmbeddedEntities(embeddedName, updateData, options) → {Promise}

Source:
Inherited From:

Update multiple Embedded Entities within this parent Entity using incremental data. Dispatch the update request to the server for handling. The result will be acknowledged to this client, and broadcast to other connected clients.

Parameters:
Name Type Description
embeddedName string

The name of the Embedded Entity class to update

updateData Array

An Array of incremental data, one per Embedded Entity, with which to update the Entity

options Object

Additional update options which modify the request

Returns:

A Promise which resolves to this Entity once the update request is successful

Type
Promise