This is more or less the whole process, from top to bottom in order:
Löve loads in boot.lua:
- require "love"
love.boot() called -- (1st xpcall in boot.lua)
- Require love.filesystem (the only module that you can't disable in conf.lua, it's mandatory)
- Parse command line arguments (they will reside in the global arg table)
- Determine if game is fused or not
- Set game identity
- Early check whether main.lua or conf.lua exists or not (if not, then errors later with the game being badly packaged)
love.init() called -- (2nd xpcall in boot.lua)
- Create default configuration settings
- Load in configuration settings from conf.lua if it exists (or if love.conf exists, even without conf.lua)
- Require modules
- Create event handlers
- Check version (compatibility related)
- Setup window (if window module is loaded)
- Set first timestep
- Require main.lua -- (Loads in the body of main.lua)
- Error if game is badly packaged.
love.run() called -- (3rd xpcall in boot.lua (if using the default love.run))
- seed löve's default PRNG
- love.load(args) -- (Actual game startup... usually)
loop:
- poll events -- (other love.___ callback functions)
- love.update(dt)
- love.draw
- sleep
Most of the lines can be safely ignored. Bold ones matter more, in terms of flow, in my opinion. Italics are optional, more or less.
Now, the two underlined lines are the two places you were asking about.
There's really only two reasons in my opinion, to use love.load instead of just calling stuff from the body of main.lua itself (different ones from what airstruck had)
1. If you put your startup stuff into love.load, you can actually reset your game/program/project/whatever by calling love.load again (that is, if you're mindful of how you code things), since under normal circumstances, loading the whole main.lua in again instead, may not be that good of an idea...
2. If you package the game into a .love, you may try to load in stuff with require, into the main.lua file scope, despite the fact that it may be badly packaged, hence you won't get the more usable error message about it being badly packged, instead you'll get one about not finding the stuff you'd require in, for example, which might not tell you obviously what the issue is.
In short, it's cleaner, but that one's just my opinion.
Also, your love.load example is a bit flawed, this would be the correct code:
Code: Select all
local example -- unless you like globals all over the place and have the brain to keep track of them all :3
function love.load()
example = "Hello world."
end
function love.update(elapse)
end
function love.draw()
love.graphics.print(example)
end