Skip to content

Switch Action

Mike-MF edited this page Jun 5, 2023 · 7 revisions

This page will explain the usage of the Switch Action function.


/*
 * Author: Mike
 * Functionality for toggling switches, when switch is "OFF" the light is red and power levels are 0, when switch is "ON" the light is green and power levels are 1 or player defined.
 * Designed for use with the "Transfer Switch" object.
 * Default state is 0 or 1
 *
 * Voltages control the power level indicators on the switch itself. Values range from 0-1.
 *
 * Switch state can be checked by getVariable
 * My_Switch getVariable [QMGVAR(switchState)];
 *
 * Call from init.sqf
 *
 * Arguments:
 * 0: Switch <OBJECT>
 * 1: Default State <NUMBER> (default: 0 (OFF))
 * 2: Voltages when on <ARRAY> (default: [1, 1])
 * 3: Action condition <CODE> (default: {true})
 *
 * Return Value:
 * None
 *
 * Example:
 * [My_Switch, 0, [0.3, 0.4]] call MFUNC(switchAction);
 * [My_Switch, 1, [0.7, 0.2], {TAC_Example}] call MFUNC(switchAction);
 */

Usage

This function is designed for the "Transfer Switch" (Land_TransferSwitch_01_F) object. It operates on an ON/OFF setting, when ON the power levels will be as player defined them to be and the light will be green, when OFF the power levels show 0 and the light is red.

For checking if the switch has been toggled use:

My_Switch getVariable [QMGVAR(switchState)] For checking if switch is ON.
!(My_Switch getVariable [QMGVAR(switchState)]) for checking if the switch is OFF.

The function also supports disabling the toggle with CODE. This can also be simply checking if the switch is not in the desired state. (See Example 2)

Call from init.sqf

Example 1:

[My_Switch, 1, [0.5, 0.7]] call MFUNC(switchAction);

Example 2:
This example covers disabling the ACE action after the switch, it starts as OFF, once the switch has been flicked the code returns true and the action disappears.

[My_Switch, 0, [1, 1], {!(My_Switch getVariable [QMGVAR(switchState)])}] call MFUNC(switchAction);
Clone this wiki locally