Optional joystick controls
Posted: Thu Apr 08, 2021 9:37 pm
Hi all,
I want to have my game use a joystick if it's plugged in but not crash if it's not. So for instance I currently have things like:
This means if my controller is plugged in I can use either joystick or keyboard controls. However, if it's not, then I get the error
Is there some way I can avoid the ugliness of having two if-then blocks for every input?
I want to have my game use a joystick if it's plugged in but not crash if it's not. So for instance I currently have things like:
Code: Select all
if joystick:isGamepadDown("dpleft") or love.keyboard.isDown("left") then
-- move left
end
In searching for solutions I found there is/was a library called 'cock' that claimed to allow a dummy joystick but it didn't seem great.attempt to index global 'joystick' (a nil value)
Is there some way I can avoid the ugliness of having two if-then blocks for every input?