love.load vs. top-level

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
peaches
Prole
Posts: 9
Joined: Tue Jul 28, 2009 7:47 pm

love.load vs. top-level

Post 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
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: love.load vs. top-level

Post 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
Help us help you: attach a .love.
peaches
Prole
Posts: 9
Joined: Tue Jul 28, 2009 7:47 pm

Re: love.load vs. top-level

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: love.load vs. top-level

Post by Robin »

Nope.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love.load vs. top-level

Post by bartbes »

I think it might create the window, not sure though.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: love.load vs. top-level

Post 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
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love.load vs. top-level

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

Who is online

Users browsing this forum: No registered users and 5 guests