Page 1 of 2

A big issue with love.update(dt)

Posted: Sun Jun 18, 2017 11:17 am
by Pospos
Edits: can't and right arrow key.

i have a big isue with update(dt), i can't(sorry for the fault) make my character move even if i press the right arrow (come on, that one was clear though)key.
I made a test to see if i can increment a value.

var = 10
rate = 3
function love.update(dt)
if love.keyboard.isDown("a") then
end
if love.keyboard.isDown("s") then
var = var + 1
end
end
function love.draw(...)
love.graphics.print(var,100,100)
end

it doesn't work. so i think i has something to do with the engine.
I've tried to download another version, but it still the same.
That's so annoying! please help me.

Re: A big issue with love.update(dt)

Posted: Sun Jun 18, 2017 11:50 am
by raidho36
Try using scancodes instead of regional keyboard characters (you get this by default).

Re: A big issue with love.update(dt)

Posted: Sun Jun 18, 2017 5:53 pm
by Pospos
it doesn't work.

Re: A big issue with love.update(dt)

Posted: Sun Jun 18, 2017 7:36 pm
by Sir_Silver
Saying "it doesn't work" doesn't tell us a whole lot about what you need help with. I ran your code, and it does exactly what you told it to do, do you mind being more specific in what you want it to do?

Image

Re: A big issue with love.update(dt)

Posted: Sun Jun 18, 2017 8:01 pm
by erasio
For example: Have you tried comparing "keypressed" key value and scancode to what you currently use? Whether or not it is equal to what you expect it to be.

Besides that. I saw no problem with the code you posted either. It was counting up by 1 per frame when "s" is pressed.

Re: A big issue with love.update(dt)

Posted: Sun Jun 18, 2017 8:26 pm
by Pospos
Yeah, i've tried all these, but the games prints the value on screen, but doesnt increment it.

Re: A big issue with love.update(dt)

Posted: Mon Jun 19, 2017 3:38 am
by zorg
Well then, i think it's time you gave us the whole file you were trying to run! :3

Re: A big issue with love.update(dt)

Posted: Mon Jun 19, 2017 7:29 pm
by Pospos
that's the whole file.
it's just a content.love with this main lua on it.

Re: A big issue with love.update(dt)

Posted: Mon Jun 19, 2017 7:44 pm
by zorg
Pospos wrote: Mon Jun 19, 2017 7:29 pm that's the whole file.
it's just a content.love with this main lua on it.
Okay, then let's decrypt your question.

By your own admission, this is your whole main.lua, and you use nothing else:

Code: Select all

var = 10 
rate = 3 
function love.update(dt)
if love.keyboard.isDown("a") then 
end
if love.keyboard.isDown("s") then 
var = var + 1
end
end
function love.draw(...)
love.graphics.print(var,100,100)
end
The first test doesn't do squat so we can remove it, you don't use the rate variable either, so after a bit of a cleanup, we get this:

Code: Select all

var = 10 

function love.update(dt)
  if love.keyboard.isDown("s") then 
    var = var + 1
  end
end

function love.draw(...)
  love.graphics.print(var,100,100)
end
Now, if you use an AZERTY or DVORAK or generally not a QWERTZ/QWERTY keyboard, you should swap the love.keyboard.isDown function with love.keyboard.isScancodeDown; otherwise it can stay.

In any case, the above code will increment your variable named var with 1 as long as you hold down the "s" key.
It will increment it more than once, of course, since the update function gets called many times each second, along with the draw function.
Pospos wrote: Sun Jun 18, 2017 11:17 am i have a big isue with update(dt), i can make my character move even if i press the right key.
By "right key", you mean the "correct" key, or the "right arrow" key?
And do you mean you can't make your character move? Because if you can, then that would imply you not having a problem...
And if you can't, and you expect the right arrow to work when you're not testing for it... then i sadly can't help you further. :P

After you read all this, feel free to alter your question so that we may give you a better answer.

Re: A big issue with love.update(dt)

Posted: Mon Jun 19, 2017 7:50 pm
by Pospos
Ok, i understand.
I don't have a QWERTY beacause i'm using a french keyboard, so i should probably use the scancode function.
but this code used to work on another keyboard non-QWERTY.