User Tools

Site Tools


usage:nodes:atc_rail

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
usage:nodes:atc_rail [2019-07-02 17:06]
82.67.173.193 added information to wiki article (2/4)
usage:nodes:atc_rail [2019-11-07 09:20]
orwell never do this
Line 108: Line 108:
   * a string, the name of a [[#passive_component_naming|passive component]].   * a string, the name of a [[#passive_component_naming|passive component]].
  
-=== POS(x, y, z) ===+== POS(x, y, z) ==
  
 A shorthand function to designate a Minetest position vector like ''{x=?, y=?, z=?}''. A shorthand function to designate a Minetest position vector like ''{x=?, y=?, z=?}''.
  
-=== getstate(pos) ===+=== Interacting with switches and other passive components ===
  
-Gets the state of a passive component at position ''pos''. The returned states are component-specific, but it is more likely to be a string.+Switches (turnouts), simple signals and mesecon switches are so-called "passive components". This is because they can be controlled passively by LuaATC (and by other means). From LuaATC, this happens via a "state" string. The states are as follows: 
 +  Switch: 
 +    "st" turnout is set to the straight branch 
 +    "cr" - turnout is set to the diverting (curved) branch 
 +  Signal: (simple signals, wall signals) 
 +    "red" - the signal is red 
 +    "green" - the signal is green 
 +  Mesecon Switch, Andrew's Cross: 
 +    "off" - switch is off, Andrew's cross does not blink 
 +    "on" - switch is on, Andrew's cross blinks and bell rings
  
-=== setstate(pos, new_state===+== getstate(pos) ==
  
-Sets the state of a passive component at position ''pos'' to the value ''new_state''. The possible states are component-specific, but it is more likely to be a string.+Gets the state of a passive component at position ''pos''. The returned states are component-specific, as described above.
  
-=== is_passive(pos) ===+== setstate(pos, new_state) == 
 + 
 +Sets the state of a passive component at position ''pos'' to the value ''new_state''. The returned states are component-specific, as described above. 
 + 
 +== is_passive(pos) ==
  
 Checks whether there is a passive component at position ''pos''. If ''pos'' is a string, checks whether the passive component with the specified name exists. Checks whether there is a passive component at position ''pos''. If ''pos'' is a string, checks whether the passive component with the specified name exists.
  
-=== interrupt(time, message) ===+=== Interrupts ===
  
-Causes the LuaAutomation mod to trigger an ''int'' event (the Advtrains equivalent of [[usage:mods:mesecons|Mesecons]]' ''interrupt'') on this component after the given ''time''in seconds, with the specified ''message''''message'' can be of any Lua data type.+These functions allow to schedule interruptsa.k.a events to be executed at a later time. They are not available in init code.
  
-This function is not available in init code.+The time counter and queue handling these interrupts is synchronized to minetest's internal step time. It is written in a very simple fashion, and is NOT secured against "interrupt bombs". Be careful! 
 +<code
 +-- an example for an "interrupt bomb" 
 +-- NEVER DO THIS! 
 +if event.int then 
 +  interrupt(1,"A"
 +  interrupt(1,"B"
 +-- run 1: {A,B} 
 +-- run 2: {A,B,A,B} 
 +-- run 3: {A,B,A,B,A,B,A,B}... 
 +</code> 
 +== interrupt(time, message) == 
 + 
 +Causes the LuaAutomation mod to trigger an ''int'' event (the Advtrains equivalent of [[usage:mods:mesecons|Mesecons]]' ''interrupt'') on this component after the given ''time'', in seconds, with the specified ''message''. ''message'' can be of any Lua data type.
  
-=== interrupt_pos(pos, message) ===+== interrupt_pos(pos, message) ==
  
 Triggers immediately an ''ext_int'' event on the active component at ''pos'' (can't be a string). ''message'' can be of any Lua data type. Triggers immediately an ''ext_int'' event on the active component at ''pos'' (can't be a string). ''message'' can be of any Lua data type.
  
-**Use with care! This may lead to expotential growth of interrupts.**+=== Railway Time ===
  
-=== digiline_send(channel, message) ===+When ''advtrains_line_automation'' is enabled, all Railway time functions are exposed as rwt.* and can safely be used in LuaATC code. 
 + 
 +For the available functions, see [[dev:lines:rwt]]. 
 + 
 +<code> 
 +--Example: print the time of the next full minute 
 +local now rwt.now() 
 +local next_minute = rwt.next_rpt(now, "01;00", 0) 
 +</code> 
 + 
 +=== 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 ''advtrains_line_automation'' is enabled. 
 + 
 +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 "interrupt bombs". There is a limit on how many interrupts can be enqueued from a single LuaATC component. At the time of this writing, this limit is set to ''1''
 + 
 +Clicking "Save" on the code edit form clears all events currently scheduled in the RWT scheduler. It does NOT clear the interrupt scheduler events. 
 + 
 +== schedule(rwtime, msg) == 
 + 
 +Triggers a ''schedule'' event AT the specified Railway Time. 
 +The time value here is an absolute value. 
 +msg can be any data type and is accessible in ''event.msg''
 + 
 +== schedule_in(rwtime, msg) == 
 + 
 +Like schedule(), but the passed time is relative. 
 +<code> 
 +  -- Example: schedule a "depart" event in 1 minute 
 +  schedule_in("01;00", "depart"
 +</code> 
 +=== Digiline === 
 + 
 +== digiline_send(channel, message) ==
  
 Sends a [[usage:mods:digilines|digiline]] message on the specified ''channel''. Sends a [[usage:mods:digilines|digiline]] message on the specified ''channel''.
Line 142: Line 204:
 This function is not available in init code. This function is not available in init code.
  
-==== Interlocking functions ====+=== Interlocking functions ===
  
 Interlocking functions are available when the ''[[usage:mods#advtrains_interlocking|advtrains_interlocking]]'' mod is enabled. Interlocking functions are available when the ''[[usage:mods#advtrains_interlocking|advtrains_interlocking]]'' mod is enabled.
  
-=== can_set_route(pos, route_name) ===+== can_set_route(pos, route_name) ==
  
 Checks whether it is possible to set the route designated by ''route_name'' from the signal at position ''pos''. Checks whether it is possible to set the route designated by ''route_name'' from the signal at position ''pos''.
Line 164: Line 226:
 > 2019-01-01 15:00:00: WARNING[Server]: [advtrains]LuaAutomation ATC interface rail at (0,0,0) : LUA Error: ...ds/advtrains/advtrains_luaautomation/environment.lua:185: No route called B at (0,0,0) > 2019-01-01 15:00:00: WARNING[Server]: [advtrains]LuaAutomation ATC interface rail at (0,0,0) : LUA Error: ...ds/advtrains/advtrains_luaautomation/environment.lua:185: No route called B at (0,0,0)
  
-=== set_route(pos, route_name) ===+== set_route(pos, route_name) ==
  
 Requests the route designated by ''route_name'' from the signal at position ''pos''. Has the same effect as clicking the "Set Route" in the formspec from the designated signal. Requests the route designated by ''route_name'' from the signal at position ''pos''. Has the same effect as clicking the "Set Route" in the formspec from the designated signal.
Line 172: Line 234:
 If the route can't be set, the signal remains red and waits for conflicting problems to be solved. Execution continues **immediately**. 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, route_name) ===+== cancel_route(pos, route_name) ==
  
 Cancels the route designated by ''route_name'' that is set from the signal at position ''pos''. Has the same effect as clicking the "Cancel Route" in the formspec from the designated signal. Cancels the route designated by ''route_name'' that is set from the signal at position ''pos''. Has the same effect as clicking the "Cancel Route" in the formspec from the designated signal.
Line 180: Line 242:
 If the route has already been canceled, nothing happens. If the route has already been canceled, nothing happens.
  
-=== get_aspect(pos) ===+== get_aspect(pos) ==
  
 Gets the aspect of the signal at ''pos''. The aspect format is described in the [[usage:nodes:signal#aspect_format|Signal]] page. Gets the aspect of the signal at ''pos''. The aspect format is described in the [[usage:nodes:signal#aspect_format|Signal]] page.
Line 196: Line 258:
 } }
 </code> </code>
- 
- 
  
 ===== Trivia ===== ===== Trivia =====
  
 The LuaAutomation ATC rail has the same texture as the [[usage:nodes:atc_controller|ATC controller rail]], but its functions are different. The LuaAutomation ATC rail has the same texture as the [[usage:nodes:atc_controller|ATC controller rail]], but its functions are different.
usage/nodes/atc_rail.txt · Last modified: 2023-12-12 02:41 by blockhead