Page 1 of 1

love.load vs. top-level

Posted: Mon Jan 04, 2010 6:48 pm
by peaches
Is there a specific reason to use love.load instead of just placing initialization code in the boostrap? e.g.

Code: Select all

local g = love.graphics

function love.load()
  g.setBackgroundColor(155, 155, 255)
  g.setColor(255, 255, 155)
end

function love.draw()
  g.print("Hello, World", 100, 100)
end
vs.

Code: Select all

local g = love.graphics
g.setBackgroundColor(155, 155, 255)
g.setColor(255, 255, 155)

function love.draw()
  g.print("Hello, World", 100, 100)
end

Re: love.load vs. top-level

Posted: Mon Jan 04, 2010 6:54 pm
by Robin
peaches wrote:Is there a specific reason to use love.load instead of just placing initialization code in the boostrap? e.g.
  1. More obvious than scattering init code all over the place
  2. You could use it to restart your game: depending on what you stuff in love.load(), just call love.load() when you want to reset the game

Re: love.load vs. top-level

Posted: Mon Jan 04, 2010 7:13 pm
by peaches
Both are achievable without the built-in callback, though. I was more curious, e.g., if the native executable modifies state in between loading the main module and invoking love.run(), (e.g. registering additonal callbacks? inspecting globals?) such that the actual behavior would be different.

Re: love.load vs. top-level

Posted: Mon Jan 04, 2010 8:02 pm
by Robin
Nope.

Re: love.load vs. top-level

Posted: Mon Jan 04, 2010 10:23 pm
by bartbes
I think it might create the window, not sure though.

Re: love.load vs. top-level

Posted: Tue Jan 05, 2010 7:13 am
by Robin
bartbes wrote:I think it might create the window, not sure though.
Not in 0.6.0 it doesn't: http://love2d.org/docs/love_run.html

Re: love.load vs. top-level

Posted: Tue Jan 05, 2010 7:58 am
by bartbes
That was useless, it proved exactly nothing. Let me look it up.

EDIT: After examining the piece of code that really mattered, the only difference is that the love console (on windows) has not been opened yet.