Class: Trigger#

Hierarchy#

  • Handle<trigger>

    ↳ Trigger

Constructors#

constructor#

new Trigger(): Trigger

Returns: Trigger

Defined in: handles/trigger.ts:10

Properties#

handle#

• Readonly handle: trigger

Inherited from: Handle.handle

Defined in: handles/handle.ts:6

Accessors#

enabled#

enabled(): boolean

Returns: boolean

Defined in: handles/trigger.ts:27

enabled(flag: boolean): void

Parameters:#

NameType
flagboolean

Returns: void

Defined in: handles/trigger.ts:19


evalCount#

evalCount(): number

Returns: number

Defined in: handles/trigger.ts:31


execCount#

execCount(): number

Returns: number

Defined in: handles/trigger.ts:39


id#

id(): 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


waitOnSleeps#

waitOnSleeps(): boolean

Marks the given trigger to wait/no longer wait for TriggerSleepActions 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 TriggerSleepActions 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:#

NameType
flagboolean

Returns: void

Defined in: handles/trigger.ts:48


eventId#

static eventId(): eventid

Returns: eventid

Defined in: handles/trigger.ts:35

Methods#

addAction#

addAction(actionFunc: function): triggeraction

Parameters:#

NameType
actionFunc() => void

Returns: triggeraction

Defined in: handles/trigger.ts:56


addCondition#

addCondition(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 attacked
t.registerAnyUnitEvent(EVENT_PLAYER_UNIT_ATTACKED)
// but only if the unit name matches
t.addCondition(Condition(() => Unit.fromHandle(GetAttacker()).name === 'Attacker Unit'))
t.addAction(() => {
//do something...
})

Parameters:#

NameTypeDescription
conditionboolexpr | () => booleanThe condition which must evaluate to true in order to run the trigger's actions.

Returns: triggercondition

Defined in: handles/trigger.ts:81


destroy#

destroy(): 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


eval#

eval(): boolean

Evaluates all functions that were added to the trigger via addCondition. All return-values from all added condition-functions are anded 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


exec#

exec(): 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


execWait#

execWait(): void

Does the same as exec but if the caller has been marked with waitOnSleeps before its execution, it will additionally wait for TriggerSleepActions 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


registerAnyUnitEvent#

registerAnyUnitEvent(whichPlayerUnitEvent: playerunitevent): void

Parameters:#

NameType
whichPlayerUnitEventplayerunitevent

Returns: void

Defined in: handles/trigger.ts:125


registerCommandEvent#

registerCommandEvent(whichAbility: number, order: string): event

Parameters:#

NameType
whichAbilitynumber
orderstring

Returns: event

Defined in: handles/trigger.ts:129


registerDeathEvent#

registerDeathEvent(whichWidget: Widget): event

Parameters:#

NameType
whichWidgetWidget

Returns: event

Defined in: handles/trigger.ts:133


registerDialogButtonEvent#

registerDialogButtonEvent(whichButton: DialogButton): event

Parameters:#

NameType
whichButtonDialogButton

Returns: event

Defined in: handles/trigger.ts:137


registerDialogEvent#

registerDialogEvent(whichDialog: Dialog): event

Parameters:#

NameType
whichDialogDialog

Returns: event

Defined in: handles/trigger.ts:141


registerEnterRegion#

registerEnterRegion(whichRegion: region, filter: null | boolexpr | function): event

Parameters:#

NameType
whichRegionregion
filternull | boolexpr | () => boolean

Returns: event

Defined in: handles/trigger.ts:145


registerFilterUnitEvent#

registerFilterUnitEvent(whichUnit: unit, whichEvent: unitevent, filter: null | boolexpr | function): event

Parameters:#

NameType
whichUnitunit
whichEventunitevent
filternull | boolexpr | () => boolean

Returns: event

Defined in: handles/trigger.ts:149


registerGameEvent#

registerGameEvent(whichGameEvent: gameevent): event

Parameters:#

NameType
whichGameEventgameevent

Returns: event

Defined in: handles/trigger.ts:153


registerGameStateEvent#

registerGameStateEvent(whichState: gamestate, opcode: limitop, limitval: number): event

Parameters:#

NameType
whichStategamestate
opcodelimitop
limitvalnumber

Returns: event

Defined in: handles/trigger.ts:157


registerLeaveRegion#

registerLeaveRegion(whichRegion: region, filter: null | boolexpr | function): event

Parameters:#

NameType
whichRegionregion
filternull | boolexpr | () => boolean

Returns: event

Defined in: handles/trigger.ts:161


registerPlayerAllianceChange#

registerPlayerAllianceChange(whichPlayer: MapPlayer, whichAlliance: alliancetype): event

Parameters:#

NameType
whichPlayerMapPlayer
whichAlliancealliancetype

Returns: event

Defined in: handles/trigger.ts:165


registerPlayerChatEvent#

registerPlayerChatEvent(whichPlayer: MapPlayer, chatMessageToDetect: string, exactMatchOnly: boolean): event

Parameters:#

NameType
whichPlayerMapPlayer
chatMessageToDetectstring
exactMatchOnlyboolean

Returns: event

Defined in: handles/trigger.ts:169


registerPlayerEvent#

registerPlayerEvent(whichPlayer: MapPlayer, whichPlayerEvent: playerevent): event

Parameters:#

NameType
whichPlayerMapPlayer
whichPlayerEventplayerevent

Returns: event

Defined in: handles/trigger.ts:173


registerPlayerKeyEvent#

registerPlayerKeyEvent(whichPlayer: MapPlayer, whichKey: oskeytype, metaKey: number, fireOnKeyDown: boolean): event

Parameters:#

NameType
whichPlayerMapPlayer
whichKeyoskeytype
metaKeynumber
fireOnKeyDownboolean

Returns: event

Defined in: handles/trigger.ts:177


registerPlayerMouseEvent#

registerPlayerMouseEvent(whichPlayer: MapPlayer, whichMouseEvent: number): event

Parameters:#

NameType
whichPlayerMapPlayer
whichMouseEventnumber

Returns: event

Defined in: handles/trigger.ts:181


registerPlayerStateEvent#

registerPlayerStateEvent(whichPlayer: MapPlayer, whichState: playerstate, opcode: limitop, limitval: number): event

Parameters:#

NameType
whichPlayerMapPlayer
whichStateplayerstate
opcodelimitop
limitvalnumber

Returns: event

Defined in: handles/trigger.ts:185


registerPlayerSyncEvent#

registerPlayerSyncEvent(whichPlayer: MapPlayer, prefix: string, fromServer: boolean): event

Parameters:#

NameType
whichPlayerMapPlayer
prefixstring
fromServerboolean

Returns: event

Defined in: handles/trigger.ts:189


registerPlayerUnitEvent#

registerPlayerUnitEvent(whichPlayer: MapPlayer, whichPlayerUnitEvent: playerunitevent, filter: null | boolexpr | function): event

Parameters:#

NameType
whichPlayerMapPlayer
whichPlayerUnitEventplayerunitevent
filternull | boolexpr | () => boolean

Returns: event

Defined in: handles/trigger.ts:193


registerTimerEvent#

registerTimerEvent(timeout: number, periodic: boolean): event

Parameters:#

NameType
timeoutnumber
periodicboolean

Returns: event

Defined in: handles/trigger.ts:198


registerTimerExpireEvent#

registerTimerExpireEvent(t: timer): event

Parameters:#

NameType
ttimer

Returns: event

Defined in: handles/trigger.ts:203


registerTrackableHitEvent#

registerTrackableHitEvent(whichTrackable: trackable): event

Parameters:#

NameType
whichTrackabletrackable

Returns: event

Defined in: handles/trigger.ts:207


registerTrackableTrackEvent#

registerTrackableTrackEvent(whichTrackable: trackable): event

Parameters:#

NameType
whichTrackabletrackable

Returns: event

Defined in: handles/trigger.ts:211


registerUnitEvent#

registerUnitEvent(whichUnit: Unit, whichEvent: unitevent): event

Parameters:#

NameType
whichUnitUnit
whichEventunitevent

Returns: event

Defined in: handles/trigger.ts:215


registerUnitInRage#

registerUnitInRage(whichUnit: unit, range: number, filter: null | boolexpr | function): event

Parameters:#

NameType
whichUnitunit
rangenumber
filternull | boolexpr | () => boolean

Returns: event

Defined in: handles/trigger.ts:219


registerUnitStateEvent#

registerUnitStateEvent(whichUnit: Unit, whichState: unitstate, opcode: limitop, limitval: number): event

Parameters:#

NameType
whichUnitUnit
whichStateunitstate
opcodelimitop
limitvalnumber

Returns: event

Defined in: handles/trigger.ts:223


registerUpgradeCommandEvent#

registerUpgradeCommandEvent(whichUpgrade: number): event

Parameters:#

NameType
whichUpgradenumber

Returns: event

Defined in: handles/trigger.ts:227


registerVariableEvent#

registerVariableEvent(varName: string, opcode: limitop, limitval: number): event

Parameters:#

NameType
varNamestring
opcodelimitop
limitvalnumber

Returns: event

Defined in: handles/trigger.ts:231


removeAction#

removeAction(whichAction: triggeraction): void

Parameters:#

NameType
whichActiontriggeraction

Returns: void

Defined in: handles/trigger.ts:235


removeActions#

removeActions(): void

Returns: void

Defined in: handles/trigger.ts:239


removeCondition#

removeCondition(whichCondition: triggercondition): void

Parameters:#

NameType
whichConditiontriggercondition

Returns: void

Defined in: handles/trigger.ts:243


removeConditions#

removeConditions(): void

Returns: void

Defined in: handles/trigger.ts:247


reset#

reset(): void

Returns: void

Defined in: handles/trigger.ts:251


triggerRegisterFrameEvent#

triggerRegisterFrameEvent(frame: Frame, eventId: frameeventtype): event

Parameters:#

NameType
frameFrame
eventIdframeeventtype

Returns: event

Defined in: handles/trigger.ts:255


fromEvent#

static fromEvent(): Trigger

Returns: Trigger

Defined in: handles/trigger.ts:259


fromHandle#

static fromHandle(handle: trigger): Trigger

Parameters:#

NameType
handletrigger

Returns: Trigger

Defined in: handles/trigger.ts:263