Controllers
The Controllers module provides utilities to manage and retrieve information about connected game controllers within a game environment, facilitating integration and interaction with external gaming devices in game development scenarios.
Usage
To use this module, add the following require at the top of your script:
Reference
getCount
Return the count of registered controllers
Returns
number: gamepad count
getList
Return the List of Ids of controllers
Returns
table: of controller IDs
getInfo
Return the information about a controller.
Parameters
id(string): Id of the controller
Returns
table: information. See example below.
Examples
local Controllers = require 'engine/controllers'
local MyBehaviour = Class.new(Behaviour)
function MyBehaviour: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 MyBehaviour