Switch Point Functions

Aus EEP Handbuch
Wechseln zu: Navigation, Suche
EEPSetSwitch() EEPSetSwitch(ID,Direction,Callback)
type: function
    -- set switch point 0067 to 1 (main line)
    EEPSetSwitch(67, 1)

    -- set switch point 0089 to 1 and call 
    EEPOnSwitch_89()
    EEPSetSwitch(89, 1, 1)
                
caller: script
defined in: EEP
parameters: two or three
returns: one
requires: EEP 10.2 plug-in 2
purpose: Switches a switch-point.
notes:
  • First argument is a numeric value representing the switch point’s ID.
  • Second argument is the switch point’s aspect.
  • If a 1 is entered as a third (optional) argument, the EEPOnSwitch_x() function for this switch is called when the direction of the switch has changed.
  • Use with care! The switch must be registerd and the corresponding function must be declared. (see next page). Careless use of this function may result in infinite loops.
  • The function returns a 1 if the switch and the demanded direction exist. It returns a 0 if either one of the two could not be found.


EEPGetSwitch() EEPGetSwitch(ID)
type: function
    currentDirection = EEPGetSwitch(1)
    if currentDirection == 0 then
        print("Switch point 1 doesn’t exist")
    elseif currentDirection == 1 then
        print("Switch point 1 set to main line")
    elseif currentDirection == 2 then
        print("Switch point 1 set to branch line")
    end
                
caller: script
defined in: EEP
parameters: one
returns: one
requires: EEP 10.2 plug-in 2
purpose: Provides the current state of a switch point.
notes:
  • Argument is the switch point’s ID.
  • Return value is a numeric representation of the switch’s current state. The value reflects the state’s position in the effects list of the switch point’s properties.
  • The return value is 0 if the switch doesn’t exist.


EEPRegisterSwitch() EEPRegisterSwitch(ID)
type: function
    EEPRegisterSwitch(1)
    function EEPOnSwitch_1(Direction)
        print("switch point 1 changed to ",
    Direction)
    end
                
caller: script
defined in: EEP
parameters: one
returns: one
requires: EEP 10.2 plug-in 2
purpose: Registers a switch for the callback function EEPOnSwitch_x(). The requirement of a registration prevents switches from triggering a callback when no appropriate function was declared.
notes:
  • The registration is mandatory for those switches which you want to trigger the EEPOnSwitch_x() function whenever the direction changes.
  • Argument is the switch’s ID.
  • Return value is 1, if the switch exists or 0 if it doesn’t exist.


EEPOnSwitch_x() EEPOnSwitch_x(Direction)
type: function
    EEPRegisterSwitch(1)
    function EEPOnSwitch_1(Direction)
        print("switch point 1 changed to ", Direction)
    end
                
caller: EEP
defined in: script
parameters: one
returns: none
requires: EEP 10.2 plug-in 2
purpose: Every aspect change induced by a contact or by manual operation (directly or in a link chain) triggers this callback function if the switch has been registerd for callbacks. However: Changing this or a linked switch’s state by Lua function will not trigger the callback, unless the third argument in that function was a 1.
notes:
  • The name of the function must not end in _x but with the switch’s ID. For switch 0034 the correct name of the function would be EEPOnSwitchl_34().
  • Please note: The leading zeroes must be omitted in the function’s name!
  • The function is called with the new switch direction as an argument. The number matches the position in the switch’s direction list as found in the switch’s properties. Use a variable of your choosing to store this value.
  • EEP requires no return value when calling this function.