Page 3 of 3

Re: Loading another script

Posted: Thu Jan 05, 2012 10:24 am
by yarickyarick
You are honestly a little away from the topic ...

Re: Loading another script

Posted: Thu Jan 05, 2012 3:35 pm
by yarickyarick
Coffey, I'm used to C #
There is a function of starting another level ... I do not remember exactly, but it seems Program.Start (lol), but to use it first in your Program need to register a couple of lines ...
I was hoping for here, too ...

Re: Loading another script

Posted: Thu Jan 05, 2012 4:29 pm
by coffee
yarickyarick wrote:Coffey, I'm used to C #
There is a function of starting another level ... I do not remember exactly, but it seems Program.Start (lol), but to use it first in your Program need to register a couple of lines ...
I was hoping for here, too ...
Sorry then, when I saw your diagram/fluxogram with jumps between files and using the typical Basic jumping flow style I thought as your friend you came also from BASIC.

Anyway back to topic, imho I don't think that the "require" is what you looking for but more something like is used for loading and execute pieces of code where data must be loaded in program. I would it do this way:

Code: Select all

if b == 100 then
load_code = love.filesystem.load( "code.lua" )	-- this loads the wanted file
run_code = load_code()					-- this run the code in that file
end

Re: Loading another script

Posted: Thu Jan 05, 2012 4:40 pm
by yarickyarick
Coffey, if needed, try =)
And now completed yet editor of the character: 3

Re: Loading another script

Posted: Thu Jan 05, 2012 5:41 pm
by Robin
It might be better to load that code once, and just call it whenever you need, as I explained a while back in this thread.

Re: Loading another script

Posted: Thu Jan 05, 2012 6:30 pm
by coffee
Robin wrote:It might be better to load that code once, and just call it whenever you need, as I explained a while back in this thread.
I suppose yarickyarick wanted to do that "IF" check once or rarely. But you right Robin I see the danger and your point to avoid reloading again and again same file if that "IF" will be a constant check. That way I could have suggested in the same way you did for the "requires":

Code: Select all

load_code = love.filesystem.load( "code.lua" )   -- this loads the wanted file
--
if b == 100 then
run_code = load_code()               -- this run the code in that file
end
But however, let's imagine too that we have to deal with a large multiple choice "if then load x file else if else if" choices. That way would be a bit unwanted have to pre-load unnecessary files before the IF.

Re: Loading another script

Posted: Thu Jan 05, 2012 10:53 pm
by Robin
coffee wrote:But however, let's imagine too that we have to deal with a large multiple choice "if then load x file else if else if" choices. That way would be a bit unwanted have to pre-load unnecessary files before the IF.
If you don't do it each frame, loading code is unlikely to have a large impact on performance, though.

Compared to images and sounds, for instance.