usage:atlatc:events
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| usage:atlatc:events [2020-01-24 09:09] – incomplete! orwell | usage:atlatc:events [2023-10-29 15:30] (current) – [approach] orwell | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==== Events ==== | + | ====== Events |
| - | In a LuaAutomation ATC controller, an event has the following format: | + | LuaATC is event-based. All code is run in an asynchronous manner. There are no blocking operations, all API functions return immediately. |
| + | |||
| + | They are not executed in parallel. You do not need to take precautions for thread-safety. Execution of LuaATC code is never interrupted externally. | ||
| + | |||
| + | Every time an event occurs that affects a LuaATC component, the whole code contained in the component is executed. It is the responsibility of the code to branch execution based on the event type. | ||
| + | |||
| + | ===== The '' | ||
| + | |||
| + | During execution of LuaATC code, the '' | ||
| <code lua> | <code lua> | ||
| event = { | event = { | ||
| Line 10: | Line 18: | ||
| </ | </ | ||
| - | You can check for a specific event type by using | + | Usually, programs will branch based on the type of event received. |
| <code lua> | <code lua> | ||
| if event.type == "< | if event.type == "< | ||
| Line 22: | Line 30: | ||
| end | end | ||
| </ | </ | ||
| + | The former allows to check the event type like in mesecons luacontrollers, | ||
| - | === int === | + | ===== Event Types ===== |
| + | |||
| + | ==== init ==== | ||
| + | The '' | ||
| + | |||
| + | ==== int ==== | ||
| <code lua> | <code lua> | ||
| event = { | event = { | ||
| Line 32: | Line 46: | ||
| } | } | ||
| </ | </ | ||
| - | Fired when an interrupt set by the '' | + | Fired when an interrupt set by the '' |
| For backwards compatibility reasons, the message is also contained in the '' | For backwards compatibility reasons, the message is also contained in the '' | ||
| - | === ext_int === | + | ==== ext_int |
| <code lua> | <code lua> | ||
| event = { | event = { | ||
| Line 43: | Line 57: | ||
| } | } | ||
| </ | </ | ||
| - | Fired when a node called '' | + | Fired when a node called '' |
| - | === digiline === | + | ==== schedule ==== |
| + | <code lua> | ||
| + | event = { | ||
| + | type = " | ||
| + | schedule = true, | ||
| + | msg = < | ||
| + | } | ||
| + | </ | ||
| + | Fired when an interrupt set by the '' | ||
| + | |||
| + | ==== digiline | ||
| <code lua> | <code lua> | ||
| event = { | event = { | ||
| Line 54: | Line 78: | ||
| } | } | ||
| </ | </ | ||
| - | Fired when the rail receives a [[usage: | + | Fired when the component |
| + | |||
| + | ==== punch ==== | ||
| + | **Applicable for:** LuaATC Operation Panel | ||
| + | <code lua> | ||
| + | event = { | ||
| + | type = " | ||
| + | punch = true, | ||
| + | name = name of puncher | ||
| + | } | ||
| + | </ | ||
| + | Fired when a player punches the operation panel. | ||
| + | |||
| + | Note: Nodes other than the operation panel don't emit the '' | ||
| + | |||
| + | ==== train ==== | ||
| + | **Applicable for:** LuaATC Rail | ||
| + | <code lua> | ||
| + | event = { | ||
| + | type = " | ||
| + | train = true, | ||
| + | id = < | ||
| + | } | ||
| + | </ | ||
| + | Fired when a train enters the rail. The field '' | ||
| + | If the world contains trains created in very early advtrains versions (< | ||
| + | |||
| + | ==== approach ==== | ||
| + | **Applicable for:** LuaATC Rail | ||
| + | <code lua> | ||
| + | event = { | ||
| + | type = " | ||
| + | approach = true, | ||
| + | id = < | ||
| + | has_entered = < | ||
| + | } | ||
| + | </ | ||
| + | Fired when a train approaches the rail. This event may be generated multiple times for the same train. | ||
| + | |||
| + | * **This function is available only when the [[# | ||
| + | |||
| + | `has_entered` is set to true when the tip of the train is already standing on the node, i.e. the " | ||
| + | |||
| + | === Approach callback mechanism === | ||
| + | |||
| + | //since version 2.3.0// | ||
| + | |||
| + | The approach callback mechanism is a new feature that allows LuaAutomation ATC rails to hook into the approach callback system, which is used by the [[usage: | ||
| + | |||
| + | To enable the feature, define the following global variable in the local environment of the ATC rail: | ||
| + | <code lua> | ||
| + | -- To enable approach callback only in arrow direction | ||
| + | __approach_callback_mode = 1 | ||
| + | |||
| + | -- To enable approach callback in both directions | ||
| + | __approach_callback_mode = 2 | ||
| + | </ | ||
| + | |||
| + | The event '' | ||
| + | |||
| + | You'll have to consider the following when setting up approach callbacks: | ||
| + | |||
| + | * Approach callbacks might be generated multiple trains for a same train. If you call '' | ||
| + | * A reference to the train will be available while executing this event, so functions such as '' | ||
| + | * The approach callbacks are executed **synchronously** during the train step. This may cause unexpected side effects when performing certain actions (such as switching turnouts, setting signals/ | ||
| + | * Accessing and setting global environment | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
usage/atlatc/events.1579856952.txt.gz · Last modified: by orwell
