Love2d Not Responding

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
CreativeName69
Prole
Posts: 1
Joined: Mon Mar 30, 2020 5:10 pm

Love2d Not Responding

Post 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
tobiasvl
Prole
Posts: 29
Joined: Mon Oct 01, 2018 4:58 pm
Location: Norway
Contact:

Re: Love2d Not Responding

Post 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.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Love2d Not Responding

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

Who is online

Users browsing this forum: No registered users and 102 guests