Controllers

Reference

controllers.getCount()

Return the count of registered controllers

Returns:

the gamepad count

Return type:

number

controllers.getList()

Return the List of Ids of controllers

Returns:

Array of controller IDs

Return type:

table

controllers.getInfo(id)

Return the information about a controller.

Parameters:

id (str) – Id of the controller

Returns:

controller information. See example below.

Return type:

table

Examples

Accessing any controllers connected to the system
local Controllers = require 'engine/controllers'

local MyEntity = Class.new(Entity)

function MyEntity:update()
    -- Get the list of currently connected controllers
    local list = Controllers.getList()

    -- Iterate through the list of connected controllers
    for _, id in ipairs(list) do
        -- Get detailed information about the controller with the given ID
        local controller = Controllers.getInfo(id)

        -- Read the horizontal and vertical axes of the controller
        local axisH = controller.axes[1]
        local axisV = controller.axes[2]

        -- Print out the controller ID and its current axis values
        print("Gamepad " .. controller.name .. ": " .. axisH .. "/" .. axisV)
    end
end

return MyEntity