load() function?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
load() function?
Hi! Why should i use the "load()" function instead of simply writing my include and load stuff on the top of the main script? And what kind of code should i put inside that function?
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: load() function?
load( ) callback documentation
This function is called once.
I'm not sure what the benefit of using load() instead of putting it outside a function is though. It might just be for reasons of scope.
This function is called once.
I'm not sure what the benefit of using load() instead of putting it outside a function is though. It might just be for reasons of scope.
Re: load() function?
Thanks! Maybe i'll include and declare constants outside it and put the rest into the load() function...
Re: load() function?
I too questioned load()
then farting around one night i noticed that some of loves stuff wasn't running outside of load() so i use it
it is redundant tho
then farting around one night i noticed that some of loves stuff wasn't running outside of load() so i use it
it is redundant tho
Re: load() function?
i just like load because of how it helps organize your game. its especially useful if your new to Lua and dont know what your doing just yet. looking back now (well, im only looking back like a week or so) i found it helpful for understanding how the game was structured but at the moment i dont need it.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: load() function?
It does help structuring the game. If all the initializing stuff is littered all over top-level, it's easy to loose oversight. Generally, the only things I place outside of load() or other functions are require()s.Pliskin09 wrote:i just like load because of how it helps organize your game.
Help us help you: attach a .love.
Re: load() function?
Ah, and here comes the second question... What's the difference between love.filesystem.include() and love.filesystem.require()? I'm using include because it reminds me C...
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: load() function?
include() can load the file multiple file, and require() makes sure it is only loaded once.
For example:
In libtest.lua:
In main.lua:
Prints:
If we replace the code in main.lua with:
It prints
Using require() is especially useful if you have multiple files, and you want them all to require() some library.
For example:
In libtest.lua:
Code: Select all
a=6
print(a)
Code: Select all
love.filesystem.include("libtest.lua")
love.filesystem.include("libtest.lua")
love.filesystem.include("libtest.lua")
Code: Select all
6
6
6
Code: Select all
love.filesystem.require("libtest.lua")
love.filesystem.require("libtest.lua")
love.filesystem.require("libtest.lua")
Code: Select all
6
Help us help you: attach a .love.
Re: load() function?
That love.filesystem.require/include rubbish will be removed, by the way. Lua's standard require function will be love.filesystem-aware from now on.
Also considering removing load(), as it is indeed redundant. Then again, people who don't want to use load() can just ignore it and put load-time stuff in the main chunk.
Also considering removing load(), as it is indeed redundant. Then again, people who don't want to use load() can just ignore it and put load-time stuff in the main chunk.
Re: load() function?
I see... love.filesystem.include() == dofile() and love.filesystem.load() = loadfile()
Who is online
Users browsing this forum: Ahrefs [Bot] and 58 guests