User Tools

Site Tools


usage:atlatc:api

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
usage:atlatc:api [2020-02-23 09:10]
orwell
usage:atlatc:api [2021-05-26 22:12] (current)
ywang
Line 73: Line 73:
  
 Causes the LuaAutomation mod to trigger an ''int'' [[usage:atlatc:events|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. Causes the LuaAutomation mod to trigger an ''int'' [[usage:atlatc:events|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.
 +
 +Use of this function is discouraged, as "fork bombs" can easily be built. Please use ''interrupt_safe()'' or make sure to ''clear_interrupts()'' in appropriate places.
 +
 +=== interrupt_safe(time, message) ===
 +
 +//since version 2.3.0//
 +
 +Like ''interrupt()'', but does not add an interrupt and returns false when an interrupt (of any type) is already present for this component. Returns true when interrupt was successfully added.
  
 ===interrupt_pos(pos, message) === ===interrupt_pos(pos, message) ===
  
 Triggers immediately an ''ext_int'' [[usage:atlatc:events|event]] on the active component at ''pos''. ''message'' can be of any Lua data type. Triggers immediately an ''ext_int'' [[usage:atlatc:events|event]] on the active component at ''pos''. ''message'' can be of any Lua data type.
 +
 +=== clear_interrupts() ===
 +
 +//since version 2.3.0//
 +
 +Removes any pending interrupts (both of type 'int' and 'ext_int') set on this node.
 +
 +==== Remote ATC ====
 +
 +//since version 2.3.0//
 +
 +In addition to ''atc_send()'' described below, LuaATC provides the possibility to send ATC commands to any train in the world knowing its train ID, by means of the following function.
 +
 +=== atc_send_to_train(train_id, command) ===
 +
 +Sends the specified [[usage:nodes:atc_controller#atc_command_syntax|ATC command]] to the train specified by its 6-digit train ID and returns ''true''. If there is no train with such an ID, returns ''false'' and does nothing.
 +
 +The ATC command is instantly applied to the train in question, regardless of where it is and what it is doing. It also cancels any active ATC command of the train.
 +
 +Calling this function from an ATC rail is independent of any train that stands on the rail and does not affect it (except of course when train_id happens to be the ID of the train on the rail).
  
 ==== Railway Time ==== ==== Railway Time ====
Line 106: Line 134:
 The time value here is an absolute value. The time value here is an absolute value.
 msg can be any data type and is accessible in ''event.msg''. msg can be any data type and is accessible in ''event.msg''.
 +<code>
 +  -- Example: schedule a "depart" event on the next full 5 minutes
 +  local now = rwt.now()
 +  local next_5minutes = rwt.next_rpt(now, "05;00", 0)
 +  schedule(next_5minutes, "depart")
 +</code>
  
 === schedule_in(rwtime, msg) === === schedule_in(rwtime, msg) ===
Line 188: Line 222:
 === atc_set_text_inside(text) === === atc_set_text_inside(text) ===
 Sets the text shown inside the train and returns ''true''. If there is no train, returns ''false'' and does nothing. Sets the text shown inside the train and returns ''true''. If there is no train, returns ''false'' and does nothing.
 +
 +=== atc_get_text_outside() / atc_get_text_inside() ===
 +Gets the outside/inside text currently set on the train.
  
 === get_line() === === get_line() ===
Line 216: Line 253:
  
 If there is no train, same behavior as [[#get_line()]] applies. If there is no train, same behavior as [[#get_line()]] applies.
 +
 +=== train_length() === 
 +Returns the number of wagons in a train.
  
 === set_shunt() === === set_shunt() ===
Line 225: Line 265:
  
 === atc_set_ars_disable(value) === === atc_set_ars_disable(value) ===
 +
 +//since version 2.3.0//
 +
 Enables (''value == false'') or disables (''value == true'') interlocking for this train. The train will not trigger automatic route setting on signals based on ARS. Enables (''value == false'') or disables (''value == true'') interlocking for this train. The train will not trigger automatic route setting on signals based on ARS.
  
 This function has essentially the same effect as the ATC command ''[[usage:nodes:atc_controller#a_enable_ARS|A<enable_ARS>]]''. This function has essentially the same effect as the ATC command ''[[usage:nodes:atc_controller#a_enable_ARS|A<enable_ARS>]]''.
- 
-**This function is experimental and currently available only in the ''[[http://git.bananach.space/advtrains.git/tree/?h=luaatc-extensions|luaatc-extensions]]'' branch of Advtrains.** 
  
 === atc_set_lzb_tsr(speed) === === atc_set_lzb_tsr(speed) ===
 +
 +//since version 2.3.0//
  
 Adds a Temporary Speed Restriction at the current rail, so that the train is passing the rail at the specified ''speed'', or at a lower speed. Adds a Temporary Speed Restriction at the current rail, so that the train is passing the rail at the specified ''speed'', or at a lower speed.
Line 239: Line 282:
   * This function is available only when the [[wiki:todo|approach callback mechanism]] is enabled.   * This function is available only when the [[wiki:todo|approach callback mechanism]] is enabled.
   * This function is only accessible during ''approach'' events   * This function is only accessible during ''approach'' events
- 
-**This function is experimental and currently available only in the ''[[http://git.bananach.space/advtrains.git/tree/?h=luaatc-extensions|luaatc-extensions]]'' branch of Advtrains.** 
  
 ==== Fields ==== ==== Fields ====
usage/atlatc/api.1582445428.txt.gz · Last modified: 2020-02-23 09:10 by orwell