Page 1 of 1

Why does this freeze Love?

Posted: Fri Jan 14, 2011 11:03 am
by Buddy4point0
I'm trying to make my game pause, so I've done:

Code: Select all

play = true

function love.run()
	while true do
		if play then
			blah blah blah
			blah blah blah
			blah blah blah
		else
			if love.keyboard.isDown("return") then
				play = true
			end
		end
	end
end
The game pauses, but when you press return to go back to the game it freezes love.
Shouldn't it just continue on with the script, and go back to the game since "play" is true again?

Re: Why does this freeze Love?

Posted: Fri Jan 14, 2011 12:01 pm
by nevon
Any reason you're redefining love.run?

Re: Why does this freeze Love?

Posted: Fri Jan 14, 2011 12:08 pm
by Robin
The problem is probably that you're not processing any events.

But what's wrong with the simpler

Code: Select all

function love.update(dt)
   if not paused then
     -- blah
   end
end

function love.keypressed(key, unicode)
    if key == 'p' then
        paused = not paused
    end
end

Re: Why does this freeze Love?

Posted: Fri Jan 14, 2011 5:42 pm
by thelinx
Don't forget to define "paused" somewhere!

Re: Why does this freeze Love?

Posted: Fri Jan 14, 2011 6:10 pm
by Taehl
In Robin's code (which I would advise using), you don't need to define 'paused'.

Re: Why does this freeze Love?

Posted: Fri Jan 14, 2011 7:06 pm
by thelinx
Taehl wrote:In Robin's code (which I would advise using), you don't need to define 'paused'.
oh yeah.

Re: Why does this freeze Love?

Posted: Fri Jan 14, 2011 8:54 pm
by Buddy4point0
nevon wrote:Any reason you're redefining love.run?
I don't know! I'm new to love, can you explain what the benefits are of redefining it and not redefining it?
Robin wrote:The problem is probably that you're not processing any events.
Well that wasn't my entire code! I was processing events lol.
Robin wrote:But what's wrong with the simpler

Code: Select all

function love.update(dt)
   if not paused then
     -- blah
   end
end

function love.keypressed(key, unicode)
    if key == 'p' then
        paused = not paused
    end
end
Okay, thanks. I used a variation of this and it works. I still don't really understand why it didn't work before though.
thelinx wrote:Don't forget to define "paused" somewhere!
Paused was never used in my code! I used "play" which would be set to true or false, and checked if it was true before the game operated.
The only thing that was outside of the "play == true" check was that if play was false, you can hit enter to set "play" back to true. :awesome:
But I've used a variation of Robins script which works great.

Re: Why does this freeze Love?

Posted: Fri Jan 14, 2011 9:01 pm
by kikito
Buddy4point0 wrote:
nevon wrote:Any reason you're redefining love.run?
I don't know! I'm new to love, can you explain what the benefits are of redefining it and not redefining it?

Redefining love.run is unnecessary 95% of the time. Unless you really know what you are doing, or you have a need that the default love.run implementation doesn't provide, you don't need to touch it at all. I once also thought I needed to modify it, but then I realized I didn't.

Instead, use love.load to load up resources (images, sounds, etc), use love.update to move things around, and love.draw for drawing them. That should be more than enough for starting with LÖVE. Once you dominate them, re-evaluate your need of modifying love.run; you will probably still don't need to.

Re: Why does this freeze Love?

Posted: Fri Jan 14, 2011 9:03 pm
by nevon
Buddy4point0 wrote:
nevon wrote:Any reason you're redefining love.run?
I don't know! I'm new to love, can you explain what the benefits are of redefining it and not redefining it?
Redefining love.run gives you more control over the main loop (updating, user input, drawing, etc.) but I'd say it's completely unnecessary for 99% of all Lövers. Most people simply use some variation of:

Code: Select all

function love.load()
    --initializing stuff
end

function love.update(dt)
    --Updating said stuff
end

function love.draw()
    --Drawing stuff
end

function love.mousereleased(x,y,button)
    --processing mouse clicks
end

function love.keyreleased(key, unicode)
    --processing key presses
end
There are other callbacks as well, such as love.focus, love.mousepressed, love.keypressed, love.joystickpressed, love.joystickreleased and love.quit, but the point is that Löve already provides you with a game loop (love.run), so unless you have a good reason to change that, you probably shouldn't.

EDIT: Argh! Ninja'd by Kikito.

Re: Why does this freeze Love?

Posted: Fri Jan 14, 2011 9:12 pm
by Buddy4point0
I see. I was modifying it so I could pause everything except the draw functions.
But now I see that if I had everything in the update function and simply paused love.update it does the same thing! :crazy: