The "right" solution is highly dependent to the project in question and is likely going to be more complex than a beginner will immediately grasp. One could hand them a perfect solution, but that doesn't help if they don't understand it.miko wrote:I think the best to start with is to do it the right way from the beginning.
Why would you need to bother? Unless you're rewriting your included stuff (in which case, why include in the first place?), why do you need to reload? Just leave it alone - Lua will see you already have it loaded, and will essentially skip re-loading it for you. Weren't you just complaining about making game-resets taking longer than absolutely necessary?miko wrote:And If I am not mistaken, you would need to unset package.loaded for every require()'d file, as Lua itself caches every require()'d file. So if part of your game setting was in a required file, you would miss it by only using loadfile('main.lua').
You shouldn't use the io library in Love. Use love.filesystem instead. Also, gf123, an alternate serializer you may be interested in is TSerial (it's smaller and simpler than JSON).miko wrote:Code: Select all
json=require 'dkjson' --save: serialized=json.encode(GameState) io.open('savedgame.json', 'w'):write(serialized) --load gameInit(json.deocde(io.open('savedgame.json', 'r'):read('*a')))