Skip to content

Lua Remap Profiles Basic Actions

Oscar-Wohlfarhrt edited this page Jul 24, 2023 · 2 revisions

Basic Remap Code Blocks

Important

Note: In case you have errors with the code blocks provided in this page, check the Advanced behavior page (Coming Soon) before raising an issue.

For this section we will use the standard format described below:

  • For emulated state variable we will use state (replace for the emulated controller state name)
  • For input state variable we will use input (replace for the Remap function first argument name)
  • For a arbitrary index of an array we will use id or index words (replace for a number)
  • For a user-defined number we will use number (replace for a variable name or with a number with a decimal point)
  • Some other things may be discribed in corresponding section

You need to understand that any code block is writed for standard use. You can, and you will need in some cases, to modified it to make it correctly work.

Input/Emulated State Variables

Axes array

state.Axis[index]

Sliders array

state.Sliders[index]

Buttons array

state.Buttons[index]

SixAxis array

Contains a processed IMU (Inertial Measurement Unit) data if controller supports it. (DualShock4 plugin provided in this repository generate this data by default).

state.SixAxis[index]

Other controller related variables

Some axis and button indices are bound to variables with friendly names to make it easy to use.
You can find this definitions here (Coming soon)

Remap Code blocks

These blocks are made to understand the behavior of Lua Remap profiles for non-programmers. If you have some experience in programing this may be intuitive.

Don't forget to call Update() function of the emulated controller after set all the state values (or following code blocks) you want.

Axis to Axis

state.Axis[index] = input.Axis[index]

Slider to Slider

state.Sliders[index] = input.Sliders[index]

Button to Button

state.Buttons[index] = input.Buttons[index]

Axis to Button

-- for positive axis value
state.Buttons[index] = input.Axis[index] > number
-- for negative axis value (index can be another of the previous line)
state.Buttons[index] = input.Axis[index] < number

Slider to Button

-- for positive slider value
state.Buttons[index] = input.Sliders[index] > number
-- for negative slider value (index can be another of the previous line)
state.Buttons[index] = input.Sliders[index] < number

Note: sliders normally do not have negative values, but there may be exceptions (check on the Input Test window to be sure)

Button to Axis

This is a bit more complicated than the previous code block, but still simply enough to be understood by everyone.

-- if you place a button variable as a condicion for an if, it will be true if the button is pressed

if input.Buttons[index] then
    -- if button is pressed
    state.Axis[index] = 1 --"1" can be replaced with any number with a decimal point or a variable name
else
    -- if button is not pressed
    state.Axis[index] = 0 --"0" can be replaced with any number with a decimal point or a variable name
end

Note: repeate the same block, but with a negative number on the button pressed code, to set a negative axis value

Button to Slider

-- if you place a button variable as a condicion for an if, it will be true if the button is pressed

if input.Buttons[index] then
    -- if button is pressed
    state.Sliders[index] = 1 --"1" can be replaced with any number with a decimal point or a variable name
else
    -- if button is not pressed
    state.Sliders[index] = 0 --"0" can be replaced with any number with a decimal point or a variable name
end

Note: repeate the same block, but with a negative number on the button pressed code, to set a negative slider value (depending on the emulated controller a negative number can be the same as 0 if emulated controller isn't calibrated correctly, case of VJoy emulated controllers)