Page 1 of 1

love.exe hungs up for some reason

Posted: Sat Nov 04, 2017 9:47 pm
by dawdejw
I was just scripting a car that was meant to rotate left when left key is pressed, but for some reason, when I'm trying to execute it, it hang up on me and stops responding! Source code:

player={x=100,y=100,speed=150,img=nil,orientation=0,size=0.5,tlitvalue=(math.pi*2)/256,offsetx,offsety}

function love.load(arg)
player.img=love.graphics.newImage('assets/CarBlue.png')
player.offsetx=player.img:getWidth()/2
player.offsety=player.img:getHeight()/2
end

function love.update(dt)
while love.keyboard.isDown(left) do
player.orientation=(player.orientation-player.tlitvalue)*dt
end
end

function love.draw(dt)
love.graphics.draw(player.img, player.x, player.y, player.orientation, player.size, player.size, player.offsetx, player.offsety)
end

Help! Also, my first post, sorry if I made something dumb ;-)

Re: love.exe hungs up for some reason

Posted: Sat Nov 04, 2017 11:46 pm
by zorg
Hi and welcome to the forums!

Your single issue with that is that while loop you put in love.update.
That function will be called by löve itself once each frame, so you don't need that loop there at all, just replace it with an if, and it should stop getting stuck in an infinite loop.

Also, do use [ code ] [ /code ] tags, makes your code more readable in posts.

Re: love.exe hungs up for some reason

Posted: Sun Nov 05, 2017 6:49 am
by dawdejw
Thank you, it works fine, I'm still learning so I didn't know. ;-)