Hello everybody,
in the moment i'm trying to build a little labyrinth game and I've been thinking about a "Reload-Function" to edit the game settings while the game is running.
So is it possible, to press a "refresh-button" during the game and reload updated files that are included in the main.lua (for example the config.lua), to change the movement of the player or the structure of the labyrinth?
I know i just could restart the Programm after editing the files, but I really want to try it this way.
Maybe someone of you has already dealt with a problem like this?
I would be very greatful for any help!
Regards
Reloading Files during Runtime
Re: Reloading Files during Runtime
I haven't tried it but, you can open and execute code with
The file has to be in the save directory for this, so this is probably most useful in development.
In this file you would probably redefine a function or change values of important variables.
Code: Select all
love.filesystem.load(filename)()
In this file you would probably redefine a function or change values of important variables.
Check out my blog on gamedev
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Reloading Files during Runtime
That is not true.micha wrote: The file has to be in the save directory for this, so this is probably most useful in development.
Re: Reloading Files during Runtime
Code: Select all
local module = require ( "module" )
-- some work here
module = require ( "updated_module" )
Re: Reloading Files during Runtime
yeah but can i do that with the config.lua during the runtime?micha wrote:I haven't tried it but, you can open and execute code withCode: Select all
love.filesystem.load(filename)()
i mean i don't want to load a file, i want to reload it after i've edited it.
raidho36 wrote:Code: Select all
local module = require ( "module" ) -- some work here module = require ( "updated_module" )
sorry but i'm not that used to lua yet and i'm having some problems understanding your idea
i'm really sorry, could you maybe explain it a litte bit more detailed for me?
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Reloading Files during Runtime
There is no reloading without loading . (Seriously though, just loading it again means you're reloading.)pilleman wrote: yeah but can i do that with the config.lua during the runtime?
i mean i don't want to load a file, i want to reload it after i've edited it.
Unless you're suggesting he changes the filename every single time, this won't work.raidho36 wrote:Code: Select all
local module = require ( "module" ) -- some work here module = require ( "updated_module" )
Re: Reloading Files during Runtime
ok so this it what i've done so far:
but i get the following error code when i press x on the keyboard:
Code: Select all
function love.keypressed(key)
.
.
.
elseif key == "x" then
love.filesystem.load(conf.lua)
end
end
Code: Select all
Error
main.lua:85: attempt to index global 'conf' (a nil value)
Traceback
...
Re: Reloading Files during Runtime
Try this:
Two things: The filename is a string. And after the love.filesystem.load you have to put two brackets, the first one to load the chunk and the second one to run it.
Code: Select all
love.filesystem.load('conf.lua')()
Check out my blog on gamedev
Re: Reloading Files during Runtime
You guys have some serious problems with reading pseudocode and using your imagination.Unless you're suggesting he changes the filename every single time, this won't work.
Re: Reloading Files during Runtime
Which part is the pseudo-code? Because the require statement doesn't work like that. It will not load the same file twice.
As Bartbes said; the only way you can use require to reload the file is if you keep changing the name, otherwise the call will be ignored. Which sounds like reasonable advice to give. Unless you meant the require function was also pseudo-code, anyway. Which wasn't really clear from your post.
As Bartbes said; the only way you can use require to reload the file is if you keep changing the name, otherwise the call will be ignored. Which sounds like reasonable advice to give. Unless you meant the require function was also pseudo-code, anyway. Which wasn't really clear from your post.
Who is online
Users browsing this forum: Google [Bot] and 4 guests