Page 1 of 1

Love2d Not Responding

Posted: Mon Mar 30, 2020 5:18 pm
by CreativeName69
Hello. This is my first post here. I am trying to change code for a Pong game a received for an assignment to implement an AI. For some reason, despite me not changing any of major components of the code, like the code that makes it load and everything, when I changed this bit of code from this:
if love.keyboard.isDown('up') then
player2.dy = -PADDLE_SPEED
elseif love.keyboard.isDown('down') then
player2.dy = PADDLE_SPEED
else
player2.dy = 0
To this:

if ball.y < player2.y
then while(player2.y ~= ball.y)
do
player2.dy = -PADDLE_SPEED
end
elseif ball.y > player2.y
then while(player2.y ~=ball.y)
do
player2.dy = PADDLE_SPEED
end
end

Love only loads a white screen and says not responding. The game worked fine before I changed it. If it changes anything, I am using the 0.10.2 version of Love. Thank you

Re: Love2d Not Responding

Posted: Sun Apr 05, 2020 8:30 pm
by tobiasvl
It means you have an infinite loop. Love never exits the while loop, which means it can't continue its regular game loop (love.update / love.draw) and stops responding.

I'm not sure what you intended to do, but if you look at the two while loops you inserted, they will run for as long as player2.y is not equal to ball.y, and as long as that is the case, it will change player2.dy. The loop does not change player2.y or ball.y, and so the condition for the loop will continue to be true, forever.

Re: Love2d Not Responding

Posted: Mon Apr 06, 2020 10:45 am
by zorg
You probably wanted to "and" together the two tests, not put one of them in "while" loops; "while" isn't a logical predicate in most programming languages, it's an iterator.