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
Love2d Not Responding
Re: Love2d Not Responding
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.
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.
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Love2d Not Responding
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.
Me and my stuff True 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.
Who is online
Users browsing this forum: azumanga, Bing [Bot] and 1 guest