Controllers¶
Reference¶
- controllers.getCount()¶
Return the count of registered controllers
- controllers.getList()¶
Return the List of Ids of controllers
- controllers.getInfo(id)¶
Return the information about a controller.
Examples¶
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