A big issue with love.update(dt)

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Pospos
Citizen
Posts: 73
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

A big issue with love.update(dt)

Post 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.
Last edited by Pospos on Mon Jun 19, 2017 7:47 pm, edited 1 time in total.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

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

Post by raidho36 »

Try using scancodes instead of regional keyboard characters (you get this by default).
User avatar
Pospos
Citizen
Posts: 73
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

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

Post by Pospos »

it doesn't work.
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

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

Post 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
Last edited by Sir_Silver on Sun Jun 18, 2017 8:46 pm, edited 1 time in total.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

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

Post 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.
User avatar
Pospos
Citizen
Posts: 73
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

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

Post by Pospos »

Yeah, i've tried all these, but the games prints the value on screen, but doesnt increment it.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post by zorg »

Well then, i think it's time you gave us the whole file you were trying to run! :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Pospos
Citizen
Posts: 73
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

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

Post by Pospos »

that's the whole file.
it's just a content.love with this main lua on it.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Pospos
Citizen
Posts: 73
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 107 guests