function love.joystickpressed( joystick, button )
if button==11 then
player.x = player.x + 1
end
end
function love.joystickpressed( joystick, button )
if button==2 then
player.y = player.y + 1
end
end
only the first button works. All the buttons are working, but only the first one. I'm working with nlove, so it's the 0.70 version of the main fork. I think, the program is working correctly and i have some issues with syntax. And is there any better way to code movement, than an if function? Because the if function basically forces the cpu to ask every frame - "Is the button pressed? Is the button pressed? Is the button pressed?" So the cpu is busy all the time with nonsense.
love.joystickpressed is callback that is activated whenever a button is pressed, it should not be used for movement because one has to press again for every pixel of movement.
Asking if it is pressed every frame is the right way to go and that must be done in the main loop.
Also you are overwriting the assignment:
function love.joystickpressed( joystick, button )
Is supposed to exist only once in your code, if you write it twice, its breaking stuff.
(If that is a an actual user request, this whole post appears to be kinda auto generated nonsense. )
Thank you for the fast reply! Sorry for my bad english, it's not my first language and sometimes i'm not able to say something in a right way.
Well now, after you wrote it, i can actually see, that i'm using 2 fuctions with the same name and yes, it is of course nonsense. So which function would be better? Joystickisdown?
Down={}
function love.joystickpressed( joystick, button )
Down[button]=true
end
function love.joystickreleased( joystick, button )
Down[button]=nil
end
love.update=function (dt)
if Down[11] then
--move
end
end
The later adds an extra table in between, which is helpful to implement one time press actions and include keyboard support and extra joypads without a lot of tinkering.
Okay, i understand, the function has two values, one for the boolean and one for the button number. But i don't get it working. Thanks for the fast reply, i'll try it tomorrow. Gute Nacht!