Game controller add

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

game_controller_id = game_controller_add(name, index, callback)

game_controller_add is used to add a game controller.


Info Game controllers can only be used on Windows and Linux platforms.

Return value

Argument Type Description
game_controller_id id This value can be used for further reference. It's good practice to store this game_controller_id in your logic code.

Arguments

# Argument Type Description
1 name String Game controller name. Can be fetched from game_controller_list call.
2 callback Function Callback which is called when a button or axis is changed on the game controller. Three arguments will be provided in the callback. Type (0=Axis, 1=Button), index (0 based offset for multiple buttons or axis) and value.

Example

function callback(type, index, value)
    print("type = " .. type .. ", index = " .. index .. ", value = " .. tostring(value))
end

list = game_controller_list()

for k, v in pairs(list) do
    game_controller_add(v, callback)
end