This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
usage:nodes:atc_rail [2019-11-07 08:20] orwell never do this |
usage:nodes:atc_rail [2023-12-12 01:41] (current) blockhead name was changed in some version or another |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | {{ http:// | + | {{ :usage: |
- | //Do anything you want with ATC rails.// | + | |
- | + | ||
- | ---- | + | |
- | FIXME This is a draft. Please improve this page by creating relevant pages, adding information and references to internal or external sources. | + | |
- | ---- | + | |
- | + | ||
- | //Note: this page has been written for Advtrains 2.0.1 TSS and Minetest 5.1.0. Examples and practices described in this page don't take advantage of improvements introduced in later releases.// | + | |
===== Properties ===== | ===== Properties ===== | ||
Line 31: | Line 24: | ||
* This node is an [[usage: | * This node is an [[usage: | ||
- | ===== Environments | + | ===== Operation |
- | + | ||
- | Each active component is assigned to an environment. This is where all data are held. Components in different environments can't interfere with each other. | + | |
- | + | ||
- | **Note: the [[# | + | |
- | + | ||
- | ==== Creating an environment ===== | + | |
- | //Main article: [[usage: | + | |
- | + | ||
- | + | ||
- | An environment is created by using '' | + | |
- | + | ||
- | ==== Setting up an environment ==== | + | |
- | //Main article: [[usage: | + | |
- | + | ||
- | + | ||
- | You've created your first LuaATC environment! If you execute ''/ | + | |
- | + | ||
- | {{: | + | |
- | + | ||
- | It allows you to edit your environment initialization code. | + | |
- | + | ||
- | * The button "Run InitCode" | + | |
- | * The button "Clear S" removes all elements from the '' | + | |
- | * The button " | + | |
- | * The button " | + | |
- | When the init code fails to execute, the '' | + | |
- | + | ||
- | More information on how to use that initialization code to do amazing things is given below. | + | |
- | + | ||
- | ===== Coding guide ===== | + | |
- | ==== Predefined global variables ==== | + | |
- | + | ||
- | The following global variables are available inside a LuaAutomation ATC rail: | + | |
- | + | ||
- | === S === | + | |
- | + | ||
- | A table shared between all components of an environment. Its contents are persistent over server restarts. Any value is allowed, except functions: | + | |
- | + | ||
- | **Do not store functions in this table. Calling them from another component may work, but they will be discarded on server shutdown and this may lead to unexpected results.** | + | |
- | + | ||
- | === F === | + | |
- | + | ||
- | A table shared between all components of an environment. Its contents are discarded on server shutdown or when the init code gets re-run. Any value is allowed, **even functions**. | + | |
- | + | ||
- | This table is not made to store data, but to provide static value and function definitions. This table should be populated by the initialization code. | + | |
- | + | ||
- | ==== Available Lua functions ==== | + | |
- | + | ||
- | The standard Lua globals are available in the LuaATC environment: | + | |
- | + | ||
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | + | ||
- | The standard Lua functions are available in the LuaATC environment: | + | |
- | + | ||
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | + | ||
- | ==== LuaAutomation-specific functions ==== | + | |
- | + | ||
- | In the following functions, all parameters named '' | + | |
- | + | ||
- | * a default Minetest position vector (like '' | + | |
- | * the '' | + | |
- | * a string, the name of a [[# | + | |
- | + | ||
- | == POS(x, y, z) == | + | |
- | + | ||
- | A shorthand function to designate a Minetest position vector like '' | + | |
- | + | ||
- | === Interacting with switches and other passive components === | + | |
- | + | ||
- | Switches (turnouts), simple signals and mesecon switches are so-called " | + | |
- | Switch: | + | |
- | " | + | |
- | " | + | |
- | Signal: (simple signals, wall signals) | + | |
- | " | + | |
- | " | + | |
- | Mesecon Switch, Andrew' | + | |
- | " | + | |
- | " | + | |
- | + | ||
- | == getstate(pos) == | + | |
- | + | ||
- | Gets the state of a passive component at position '' | + | |
- | + | ||
- | == setstate(pos, | + | |
- | + | ||
- | Sets the state of a passive component at position '' | + | |
- | + | ||
- | == is_passive(pos) == | + | |
- | + | ||
- | Checks whether there is a passive component at position '' | + | |
- | + | ||
- | === Interrupts === | + | |
- | + | ||
- | These functions allow to schedule interrupts, a.k.a events to be executed at a later time. They are not available in init code. | + | |
- | + | ||
- | The time counter and queue handling these interrupts is synchronized to minetest' | + | |
- | < | + | |
- | -- an example for an " | + | |
- | -- NEVER DO THIS! | + | |
- | if event.int then | + | |
- | interrupt(1," | + | |
- | interrupt(1," | + | |
- | -- run 1: {A,B} | + | |
- | -- run 2: {A,B,A,B} | + | |
- | -- run 3: {A, | + | |
- | </ | + | |
- | == interrupt(time, | + | |
- | + | ||
- | Causes the LuaAutomation mod to trigger an '' | + | |
- | + | ||
- | == interrupt_pos(pos, | + | |
- | + | ||
- | Triggers immediately an '' | + | |
- | + | ||
- | === Railway Time === | + | |
- | + | ||
- | When '' | + | |
- | + | ||
- | For the available functions, see [[dev: | + | |
- | + | ||
- | < | + | |
- | --Example: print the time of the next full minute | + | |
- | local now = rwt.now() | + | |
- | local next_minute = rwt.next_rpt(now, | + | |
- | </ | + | |
- | + | ||
- | === Railway Time Scheduler === | + | |
- | + | ||
- | This is a separate schedule queue. In contrast to the interrupt system, which is the original and established way to schedule interrupts, it relies on the Railway Time system and therefore is only accessible when '' | + | |
- | + | ||
- | There are two important considerations to this: | + | |
- | + | ||
- | - While the interrupt system is always synchronized to minetest step time, the RWT scheduler follows the RWT time flow. In particular, this means that you must be able to handle "time jumps" that occur when RWT is set up to adapt to real time. | + | |
- | - The RWT scheduler has a built-in protection against " | + | |
- | + | ||
- | Clicking " | + | |
- | + | ||
- | == schedule(rwtime, | + | |
- | + | ||
- | Triggers a '' | + | |
- | The time value here is an absolute value. | + | |
- | msg can be any data type and is accessible in '' | + | |
- | + | ||
- | == schedule_in(rwtime, | + | |
- | + | ||
- | Like schedule(), but the passed time is relative. | + | |
- | < | + | |
- | -- Example: schedule a " | + | |
- | schedule_in(" | + | |
- | </ | + | |
- | === Digiline === | + | |
- | + | ||
- | == digiline_send(channel, | + | |
- | + | ||
- | Sends a [[usage: | + | |
- | + | ||
- | This function is not available in init code. | + | |
- | + | ||
- | === Interlocking functions === | + | |
- | + | ||
- | Interlocking functions are available when the '' | + | |
- | + | ||
- | == can_set_route(pos, | + | |
- | + | ||
- | Checks whether it is possible to set the route designated by '' | + | |
- | + | ||
- | It emits a warning and halts execution of Lua code in the following cases: | + | |
- | + | ||
- | * the node at specified position is not a signal: | + | |
- | + | ||
- | > 2019-01-01 15:00:00: WARNING[Server]: | + | |
- | + | ||
- | * '' | + | |
- | + | ||
- | > 2019-01-01 15:00:00: WARNING[Server]: | + | |
- | + | ||
- | * the specified route does not exist: | + | |
- | + | ||
- | > 2019-01-01 15:00:00: WARNING[Server]: | + | |
- | + | ||
- | == set_route(pos, | + | |
- | + | ||
- | Requests the route designated by '' | + | |
- | + | ||
- | Same warnings apply as for '' | + | |
- | + | ||
- | If the route can't be set, the signal remains red and waits for conflicting problems to be solved. Execution continues **immediately**. | + | |
- | + | ||
- | == cancel_route(pos, | + | |
- | + | ||
- | Cancels the route designated by '' | + | |
- | + | ||
- | Same warnings apply as for '' | + | |
- | + | ||
- | If the route has already been canceled, nothing happens. | + | |
- | == get_aspect(pos) == | + | The LuaATC Rail is an active LuaATC component. It holds Lua code that is executed on specific [[usage: |
- | Gets the aspect of the signal at '' | + | Every LuaATC rail must belong to an [[usage:atlatc:environment|Environment]]. You can select the active environment using the dropdown on the top left. |
- | Same warnings apply as for '' | + | //Note: you have to create an environment before LuaATC components can be used. See [[usage: |
- | ==== Events | + | ===== API ===== |
- | In a LuaAutomation ATC controller, an event has the following format: | + | For details how to program LuaATC rails, refer to the [[usage: |
- | <code lua> | + | {{indexmenu>usage: |
- | event = { | + | |
- | type = "< | + | |
- | < | + | |
- | -- additional content | + | |
- | } | + | |
- | </ | + | |
===== Trivia ===== | ===== Trivia ===== | ||
- | The LuaAutomation ATC rail has the same texture as the [[usage: | + | The LuaAutomation ATC rail has the same texture as the [[usage: |