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:

Loading another script

Post by yarickyarick »

Hi, guys!
I'm from Ukraine, so don `t know English, I will rely on its leash basic knowledge of the language ... Immediately ask forgiveness for the poor knowledge of English ...
I'm 15 years old and my name is Yaroslav!
Now to business ...
I started razrabatovat their first game at Love (Previously, he worked only for Basic and C like) and collided with a problem that occurs in support of several scripts, is not very convenient to load a script from a file into a file and there propisovat believe that all zanogo ... I do not see the difference between downloading the file and write the code directly into the main script ...
I think it would be much more convenient to write this function love.run.script ("script.lua") and it made a transition to another script, you will agree it's much easier ... though not in all cases, but most ...
I and many will be very happy if you do it.
Thanks in advance!
PS I wish you happiness, joy and all the Keep it in the new year and may have already passed your Christmas to you all!
Sincerely, Yaroslav.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Loading another script

Post by nevon »

I think you're talking about require.
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Loading another script

Post by Ellohir »

Wait, you can use require to jump to a file and later come back? In the middle of any function?

Sounds like a GOTO. Which is definately not classy, but sometimes useful xD
yarickyarick
Prole
Posts: 15
Joined: Fri Dec 30, 2011 9:48 pm
Contact:

Re: Loading another script

Post by yarickyarick »

I would be interested to see it in Love, but not in direct Lua ...
By the way obviously looked at what you showed me a leash require loading the script file, but I tell you about the transition between the scripts ...
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Loading another script

Post by bartbes »

It loads and runs the file, because that how an interpreter works, everything on the top level will be executed (but more importantly, functions will be defined).
Also, this works for love as well, lua's require supports adding searchers, and that's exactly what we've done.
yarickyarick
Prole
Posts: 15
Joined: Fri Dec 30, 2011 9:48 pm
Contact:

Re: Loading another script

Post by yarickyarick »

Hmm ...
Well then I apologize ... My friend just told me that there is a leash one way, so that complex + Question: If you put the expression in the events provided (the one in the "if" after "then"), it also runs another script? Without error?
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 »

What is your question?
Help us help you: attach a .love.
yarickyarick
Prole
Posts: 15
Joined: Fri Dec 30, 2011 9:48 pm
Contact:

Re: Loading another script

Post by yarickyarick »

Code: Select all

if blabla = 123
then
require script.lua
end
You can do this?
this will allow me to immediately perform all the functions of the script, without the functions of this script?
Ie how to transition from one file to the second ...
bottles as a transition between levels in the game ...
__________________________________
And I apologize that there was no these 3 days ...
Just did not have access to your site, because of its provider ... :x
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Loading another script

Post by MarekkPie »

I think I understand your question.

Code: Select all

-- File script.lua
local function A(n)
  return n * n
end

local function B(n)
  return A(5) + n
end

return B(7)

Code: Select all

-- In main.lua
if varA == 100 then
  varB = require "script"
end
If that is what you are asking, then yes.
yarickyarick
Prole
Posts: 15
Joined: Fri Dec 30, 2011 9:48 pm
Contact:

Re: Loading another script

Post by yarickyarick »

I did not understand a bit and then n * n, VarB and the like ...
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests