So my question is, how is it used? Of course, I know that it only happens once, loads stuff and all that, but wouldn't it be the same if you put the stuff that needs to load at the start of the code? Also, if you want to use local, then if you use it in love.load, you can use it only there, which is useless like 50% of the time.
So is the love.load function actually needed? Is there something I'm not getting?
About the love.load function
- BrotSagtMist
- Party member
- Posts: 659
- Joined: Fri Aug 06, 2021 10:30 pm
Re: About the love.load function
Well its called AFTER everything in the main code, you can use it for ordering a bit.
But no, it is not really useful at all. Its just an convention that makes understanding other peoples code easier.
The same uselessness applies to every other love core function. Have a look at:https://love2d.org/wiki/love.run
This is the only place these names are used. There is no _need_ to use draw or update at all (and i dont), but if you are sharing code in this forum and it does not follow this form of functions splited by purpose then you will likely get no support for it.
Ah btw there is a name for a local that is accessable everywhere: Its a global.
But no, it is not really useful at all. Its just an convention that makes understanding other peoples code easier.
The same uselessness applies to every other love core function. Have a look at:https://love2d.org/wiki/love.run
This is the only place these names are used. There is no _need_ to use draw or update at all (and i dont), but if you are sharing code in this forum and it does not follow this form of functions splited by purpose then you will likely get no support for it.
Ah btw there is a name for a local that is accessable everywhere: Its a global.
obey
Re: About the love.load function
Brot summed it up. I use love.load simply to keep my code tidy.
A local inside ANY function scopes it to that function. If that's not what you want then don't do that.
A local inside ANY function scopes it to that function. If that's not what you want then don't do that.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: About the love.load function
One thing that might be useful about love.load is that if you restart your game programmatically, love.load will be called again; i'm not sure if the body of main.lua will though.
Also, you can still define locals in the main body outside of any function, but assign values inside love.load, that works as intended.
Also, you can still define locals in the main body outside of any function, but assign values inside love.load, that works as intended.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: About the love.load function
The whole Lua state is restarted. All code runs again (including conf.lua).
In fact, if you don't have a main.lua, only a conf.lua, then defining love.load is more useful since no LÖVE modules are loaded yet in the main chunk, so you can't load images etc. at that point.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
Re: About the love.load function
You can declare locals outside and assign them inside love.load:
Then they are local to the Lua file they are in (main.lua for example).
There was a time when the random number generator was initialized between loading main.lua and executing love.load, so if you used random numbers in the top scope of main.lua, they weren't random. That's no longer the case.
Code: Select all
local img
function love.load()
img = love.graphics.newImage(...)
end
There was a time when the random number generator was initialized between loading main.lua and executing love.load, so if you used random numbers in the top scope of main.lua, they weren't random. That's no longer the case.
Re: About the love.load function
Personally, I either don't use love.load at all, or else I use it as pgimeno stated - declare things at the top of main.lua, and assign them elsewhere. Helps me keep my code clean(ish).
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Who is online
Users browsing this forum: Google [Bot], slime and 5 guests