#
Class: Trigger#
HierarchyHandle<trigger>
↳ Trigger
#
Constructors#
constructornew Trigger(): Trigger
Returns: Trigger
Defined in: handles/trigger.ts:10
#
Properties#
handle• Readonly
handle: trigger
Defined in: handles/handle.ts:6
#
Accessors#
enabledenabled(): boolean
Returns: boolean
Defined in: handles/trigger.ts:27
enabled(flag: boolean): void
#
Parameters:Name | Type |
---|---|
flag | boolean |
Returns: void
Defined in: handles/trigger.ts:19
#
evalCountevalCount(): number
Returns: number
Defined in: handles/trigger.ts:31
#
execCountexecCount(): number
Returns: number
Defined in: handles/trigger.ts:39
#
idid(): number
Get the unique ID of the handle. The ID is recycled once you destroy the object.
Returns: number
The unique ID of a handle object.
Defined in: handles/handle.ts:18
#
waitOnSleepswaitOnSleeps(): boolean
Marks the given trigger to wait/no longer wait for TriggerSleepAction
s in sub trigger executions started via TriggerExecuteWait
.
Since this is an attribute of the execution rather than the trigger object, this affects future runs of the given trigger, and not
those already started.
Returns: boolean
Defined in: handles/trigger.ts:52
waitOnSleeps(flag: boolean): void
Marks the given trigger to wait/no longer wait for TriggerSleepAction
s in sub trigger executions started via TriggerExecuteWait
.
Since this is an attribute of the execution rather than the trigger object, this affects future runs of the given trigger, and not
those already started.
#
Parameters:Name | Type |
---|---|
flag | boolean |
Returns: void
Defined in: handles/trigger.ts:48
#
eventIdstatic eventId(): eventid
Returns: eventid
Defined in: handles/trigger.ts:35
#
Methods#
addActionaddAction(actionFunc: function): triggeraction
#
Parameters:Name | Type |
---|---|
actionFunc | () => void |
Returns: triggeraction
Defined in: handles/trigger.ts:56
#
addConditionaddCondition(condition: boolexpr | function): triggercondition
Adds a new condition to the trigger.
Adding more conditions later wil join them by AND (that means all conditions need to evaluate to true
)
example
const t = new Trigger()
// trigger fires if a unit is attackedt.registerAnyUnitEvent(EVENT_PLAYER_UNIT_ATTACKED)
// but only if the unit name matchest.addCondition(Condition(() => Unit.fromHandle(GetAttacker()).name === 'Attacker Unit'))
t.addAction(() => { //do something...})
#
Parameters:Name | Type | Description |
---|---|---|
condition | boolexpr | () => boolean | The condition which must evaluate to true in order to run the trigger's actions. |
Returns: triggercondition
Defined in: handles/trigger.ts:81
#
destroydestroy(): void
bug
Do not destroy the current running Trigger (when waits are involved)
as it can cause handle stack corruption as documented here.
Returns: void
Defined in: handles/trigger.ts:89
#
evaleval(): boolean
Evaluates all functions that were added to the trigger via addCondition
.
All return-values from all added condition-functions are and
ed together as the final return-value.
Returns the boolean value of the return value from the condition-function.
So if 0/0.0/null would be returned in the condition-function, eval
would return false. Note that ""
would return true
.
note
If a condition-function crashes the thread or does not return any value eval
will return false.
note
If you want to return false for a condition-function that returns string (for whatever reason) return null
instead of ""
note
All functions added via addCondition
are run. There is no short-circuting. If you want short-circuting use And
or Or
.
note
All functions added via addCondition
are run in the order they were added.
Returns: boolean
Defined in: handles/trigger.ts:104
#
execexec(): void
Calls the actions of a trigger in a new execution context. Control will return to the caller when the trigger has finished or has been suspended via TriggerSleepAction.
Returns: void
Defined in: handles/trigger.ts:112
#
execWaitexecWait(): void
Does the same as exec
but if the caller has been marked with waitOnSleeps
before its
execution, it will additionally wait for TriggerSleepAction
s of the callee, so this really ensures that
the callee has finished. If there was a TriggerSleepAction
, there will be a short delay before returning.
Returns: void
Defined in: handles/trigger.ts:121
#
registerAnyUnitEventregisterAnyUnitEvent(whichPlayerUnitEvent: playerunitevent): void
#
Parameters:Name | Type |
---|---|
whichPlayerUnitEvent | playerunitevent |
Returns: void
Defined in: handles/trigger.ts:125
#
registerCommandEventregisterCommandEvent(whichAbility: number, order: string): event
#
Parameters:Name | Type |
---|---|
whichAbility | number |
order | string |
Returns: event
Defined in: handles/trigger.ts:129
#
registerDeathEventregisterDeathEvent(whichWidget: Widget): event
#
Parameters:Name | Type |
---|---|
whichWidget | Widget |
Returns: event
Defined in: handles/trigger.ts:133
#
registerDialogButtonEventregisterDialogButtonEvent(whichButton: DialogButton): event
#
Parameters:Name | Type |
---|---|
whichButton | DialogButton |
Returns: event
Defined in: handles/trigger.ts:137
#
registerDialogEventregisterDialogEvent(whichDialog: Dialog): event
#
Parameters:Name | Type |
---|---|
whichDialog | Dialog |
Returns: event
Defined in: handles/trigger.ts:141
#
registerEnterRegionregisterEnterRegion(whichRegion: region, filter: null | boolexpr | function): event
#
Parameters:Name | Type |
---|---|
whichRegion | region |
filter | null | boolexpr | () => boolean |
Returns: event
Defined in: handles/trigger.ts:145
#
registerFilterUnitEventregisterFilterUnitEvent(whichUnit: unit, whichEvent: unitevent, filter: null | boolexpr | function): event
#
Parameters:Name | Type |
---|---|
whichUnit | unit |
whichEvent | unitevent |
filter | null | boolexpr | () => boolean |
Returns: event
Defined in: handles/trigger.ts:149
#
registerGameEventregisterGameEvent(whichGameEvent: gameevent): event
#
Parameters:Name | Type |
---|---|
whichGameEvent | gameevent |
Returns: event
Defined in: handles/trigger.ts:153
#
registerGameStateEventregisterGameStateEvent(whichState: gamestate, opcode: limitop, limitval: number): event
#
Parameters:Name | Type |
---|---|
whichState | gamestate |
opcode | limitop |
limitval | number |
Returns: event
Defined in: handles/trigger.ts:157
#
registerLeaveRegionregisterLeaveRegion(whichRegion: region, filter: null | boolexpr | function): event
#
Parameters:Name | Type |
---|---|
whichRegion | region |
filter | null | boolexpr | () => boolean |
Returns: event
Defined in: handles/trigger.ts:161
#
registerPlayerAllianceChangeregisterPlayerAllianceChange(whichPlayer: MapPlayer, whichAlliance: alliancetype): event
#
Parameters:Name | Type |
---|---|
whichPlayer | MapPlayer |
whichAlliance | alliancetype |
Returns: event
Defined in: handles/trigger.ts:165
#
registerPlayerChatEventregisterPlayerChatEvent(whichPlayer: MapPlayer, chatMessageToDetect: string, exactMatchOnly: boolean): event
#
Parameters:Name | Type |
---|---|
whichPlayer | MapPlayer |
chatMessageToDetect | string |
exactMatchOnly | boolean |
Returns: event
Defined in: handles/trigger.ts:169
#
registerPlayerEventregisterPlayerEvent(whichPlayer: MapPlayer, whichPlayerEvent: playerevent): event
#
Parameters:Name | Type |
---|---|
whichPlayer | MapPlayer |
whichPlayerEvent | playerevent |
Returns: event
Defined in: handles/trigger.ts:173
#
registerPlayerKeyEventregisterPlayerKeyEvent(whichPlayer: MapPlayer, whichKey: oskeytype, metaKey: number, fireOnKeyDown: boolean): event
#
Parameters:Name | Type |
---|---|
whichPlayer | MapPlayer |
whichKey | oskeytype |
metaKey | number |
fireOnKeyDown | boolean |
Returns: event
Defined in: handles/trigger.ts:177
#
registerPlayerMouseEventregisterPlayerMouseEvent(whichPlayer: MapPlayer, whichMouseEvent: number): event
#
Parameters:Name | Type |
---|---|
whichPlayer | MapPlayer |
whichMouseEvent | number |
Returns: event
Defined in: handles/trigger.ts:181
#
registerPlayerStateEventregisterPlayerStateEvent(whichPlayer: MapPlayer, whichState: playerstate, opcode: limitop, limitval: number): event
#
Parameters:Name | Type |
---|---|
whichPlayer | MapPlayer |
whichState | playerstate |
opcode | limitop |
limitval | number |
Returns: event
Defined in: handles/trigger.ts:185
#
registerPlayerSyncEventregisterPlayerSyncEvent(whichPlayer: MapPlayer, prefix: string, fromServer: boolean): event
#
Parameters:Name | Type |
---|---|
whichPlayer | MapPlayer |
prefix | string |
fromServer | boolean |
Returns: event
Defined in: handles/trigger.ts:189
#
registerPlayerUnitEventregisterPlayerUnitEvent(whichPlayer: MapPlayer, whichPlayerUnitEvent: playerunitevent, filter: null | boolexpr | function): event
#
Parameters:Name | Type |
---|---|
whichPlayer | MapPlayer |
whichPlayerUnitEvent | playerunitevent |
filter | null | boolexpr | () => boolean |
Returns: event
Defined in: handles/trigger.ts:193
#
registerTimerEventregisterTimerEvent(timeout: number, periodic: boolean): event
#
Parameters:Name | Type |
---|---|
timeout | number |
periodic | boolean |
Returns: event
Defined in: handles/trigger.ts:198
#
registerTimerExpireEventregisterTimerExpireEvent(t: timer): event
#
Parameters:Name | Type |
---|---|
t | timer |
Returns: event
Defined in: handles/trigger.ts:203
#
registerTrackableHitEventregisterTrackableHitEvent(whichTrackable: trackable): event
#
Parameters:Name | Type |
---|---|
whichTrackable | trackable |
Returns: event
Defined in: handles/trigger.ts:207
#
registerTrackableTrackEventregisterTrackableTrackEvent(whichTrackable: trackable): event
#
Parameters:Name | Type |
---|---|
whichTrackable | trackable |
Returns: event
Defined in: handles/trigger.ts:211
#
registerUnitEventregisterUnitEvent(whichUnit: Unit, whichEvent: unitevent): event
#
Parameters:Name | Type |
---|---|
whichUnit | Unit |
whichEvent | unitevent |
Returns: event
Defined in: handles/trigger.ts:215
#
registerUnitInRageregisterUnitInRage(whichUnit: unit, range: number, filter: null | boolexpr | function): event
#
Parameters:Name | Type |
---|---|
whichUnit | unit |
range | number |
filter | null | boolexpr | () => boolean |
Returns: event
Defined in: handles/trigger.ts:219
#
registerUnitStateEventregisterUnitStateEvent(whichUnit: Unit, whichState: unitstate, opcode: limitop, limitval: number): event
#
Parameters:Name | Type |
---|---|
whichUnit | Unit |
whichState | unitstate |
opcode | limitop |
limitval | number |
Returns: event
Defined in: handles/trigger.ts:223
#
registerUpgradeCommandEventregisterUpgradeCommandEvent(whichUpgrade: number): event
#
Parameters:Name | Type |
---|---|
whichUpgrade | number |
Returns: event
Defined in: handles/trigger.ts:227
#
registerVariableEventregisterVariableEvent(varName: string, opcode: limitop, limitval: number): event
#
Parameters:Name | Type |
---|---|
varName | string |
opcode | limitop |
limitval | number |
Returns: event
Defined in: handles/trigger.ts:231
#
removeActionremoveAction(whichAction: triggeraction): void
#
Parameters:Name | Type |
---|---|
whichAction | triggeraction |
Returns: void
Defined in: handles/trigger.ts:235
#
removeActionsremoveActions(): void
Returns: void
Defined in: handles/trigger.ts:239
#
removeConditionremoveCondition(whichCondition: triggercondition): void
#
Parameters:Name | Type |
---|---|
whichCondition | triggercondition |
Returns: void
Defined in: handles/trigger.ts:243
#
removeConditionsremoveConditions(): void
Returns: void
Defined in: handles/trigger.ts:247
#
resetreset(): void
Returns: void
Defined in: handles/trigger.ts:251
#
triggerRegisterFrameEventtriggerRegisterFrameEvent(frame: Frame, eventId: frameeventtype): event
#
Parameters:Name | Type |
---|---|
frame | Frame |
eventId | frameeventtype |
Returns: event
Defined in: handles/trigger.ts:255
#
fromEventstatic fromEvent(): Trigger
Returns: Trigger
Defined in: handles/trigger.ts:259
#
fromHandlestatic fromHandle(handle: trigger): Trigger
#
Parameters:Name | Type |
---|---|
handle | trigger |
Returns: Trigger
Defined in: handles/trigger.ts:263