Loading another script

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
yarickyarick
Prole
Posts: 15
Joined: Fri Dec 30, 2011 9:48 pm
Contact:

Re: Loading another script

Post by yarickyarick »

You are honestly a little away from the topic ...
yarickyarick
Prole
Posts: 15
Joined: Fri Dec 30, 2011 9:48 pm
Contact:

Re: Loading another script

Post 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 ...
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Loading another script

Post 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
yarickyarick
Prole
Posts: 15
Joined: Fri Dec 30, 2011 9:48 pm
Contact:

Re: Loading another script

Post by yarickyarick »

Coffey, if needed, try =)
And now completed yet editor of the character: 3
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Loading another script

Post 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.
Help us help you: attach a .love.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Loading another script

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Loading another script

Post 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.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests