tried to use for the first time the Controller features of the API to send keypresses to an addon and found somewhat the example given in the Wiki rather confusing
I had to struggle through trial and errors to figure out how to address a specific controller.
I think that the Wiki should be more explicit for that matter.
The current example given affects only ONE callback whatever the controller, so in case of multiple controllers the same button number on different controller is used.
Code: Select all
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
Game controller list
game_controller_list String[] The array is a list of strings with all the game controllers. You can use an item in this list for the game_controller_add function.
Example:
Code: Select all
list = game_controller_list()
for k, v in pairs(list) do
print("List index: "..k.." /Name of the Controller: "..v)
end
game_controller_add
Example:
Code: Select all
function callback_controller_0(type, index, value) -- input from the controller 0
print(list[0]..":type = " .. type .. ", index = " .. index .. ", value = " .. tostring(value))
-- insert functions to interact with the sim
end
function callback_controller_1(type, index, value) -- input from the controller 1
print(list[1].." :type = " .. type .. ", index = " .. index .. ", value = " .. tostring(value))
-- insert functions to interact with the sim
end
list = game_controller_list()
-- for debug purposes you can uncomment these lines
-- for k, v in pairs(list) do
-- print("List index: "..k.." /Name of the Controller: "..v)
-- end
game_controller_add("TCA Q-Eng 1&2", callback0) -- new controller added by name
game_controller_add(list[1], callback1) -- new controller added by list reference