When to use love.load()?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
vine
Prole
Posts: 5
Joined: Sun Dec 02, 2012 4:59 pm

When to use love.load()?

Post by vine »

I don't understand the purpose of love.load().
It loads all data within the function before the window is created, but what's the point in using it, as opposed to simply putting data outside the function?

ie:

Code: Select all

rat = love.graphics.newImage("rat.png")
VS

Code: Select all

function love.load()
    rat = love.graphics.newImage("rat.png")
end
What benefit does this have, and when is it appropriate to use?
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: When to use love.load()?

Post by Boolsheet »

love.load is mainly a design thing that lets you separate the loading part of the game into its own function. There is one difference, however. The random seed gets initialized just before love.load gets called. If some code uses math.random before that, it will always get the same sequence.

Also, main.lua and love.load should get executed after the window has been created. Unless you disabled it in conf.lua and create the window yourself.
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests