TODO: explain that properties can be get/set from the definition.
Summary
Section titled “Summary”Properties
- cancellable
booleanWhether the ability can be cancelled or not. […]
-
The Entity that spawned this ability. […]
-
An optional Entity that "owns" this ability. […]
- stack
numberConvenience attribute that allows for ability stacking. […]
Methods
- complete
()Completes the ability. […]
- on_change
(attribute: string, callback: ((attribute: string, old: any, data: any) -> ())?, data: any)Assigns a callback to be called after an ability attribute changes. […]
Inherited Methods from Entity
- despawn
()Despawns this entity. […]
- is_ability
() → booleanWhether this entity is an Ability. […]
- as_ability
() → Ability?Typecasts this entity to an Ability, if possible. […]
- to_ability
() → AbilityForces this entity into an Ability type. […]
- is_unit
() → booleanWhether this entity is a Unit. […]
-
Typecasts this entity to a Unit, if possible. […]
-
Forces this entity into a Unit type. […]
Properties
Section titled “Properties”cancellable
Section titled “cancellable”cancellable: boolean
Whether the ability can be cancelled or not.
TODO: explain what cancellation means.
source Read only
Section titled “source Read only ”source: Entity?
The Entity that spawned this ability. nil if unknown.
owner: Entity?
An optional Entity that "owns" this ability. The ability will be automatically removed when its owner is despawned. Useful for applying abilities in the range of a unit.
Example
Section titled “Example”Adds an ability "example.lua" on all units in range. The ability will be automatically removed when the unit gets out of range or this unit is despawned.
function on_enter_area(unit: Unit, holder: AbilityHolder, ability: Ability) local added_ability = unit.insert_ability("example.lua") added_ability.owner = abilityend
function on_exit_area(unit: Unit, holder: AbilityHolder, ability: Ability) unit:remove_abilities_from(ability)endstack: number
Convenience attribute that allows for ability stacking.
When set to 0, the ability will automatically be removed.
Additionally, any changes to the stack will trigger the [script.on_stack] event.
Can be used for status effect abilities such as Poison or Weak.
Do note that [Ability.on_change] does not track changes to the stack. Use [script.on_stack] instead.
Methods
Section titled “Methods”complete
Section titled “complete”Ability:complete()
Completes the ability.
TODO: explain what completing an ability means.
on_change
Section titled “on_change”Ability:on_change(attribute: string, callback: ((attribute: string, old: any, data: any) -> ())?, data: any)
Assigns a callback to be called after an ability attribute changes.
The callback will be called with the following arguments:
attribute: The name of the attribute that changed.old: The old value of the attribute.data: The additional data passed todata.
You can set the callback to nil to remove it.
Multiple callbacks can't be assigned to the same attribute. Newly added callbacks will replace the previous one.
Parameters
- attribute Required
stringThe name of the attribute to listen to changes for.
- callback Optional
((attribute: string, old: any, data: any) -> ())?The function to call when
attributechanges. - data Required
anyAdditional data to pass to the callback.
Examples
Section titled “Examples”ability:on_change("foo", function(attribute, old) print( "changed " .. attribute .. " from " .. tostring(old) .. " to " .. tostring(ability[attribute]) )end)local function damage(attribute, old, data) local unit = data :: Unit unit:damage(ability[attribute])end
script.on_insert = function(holder, ability) ability:on_change("stack", damage, holder)end