Page 1 of 3

Loading another script

Posted: Fri Dec 30, 2011 10:03 pm
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.

Re: Loading another script

Posted: Sat Dec 31, 2011 8:11 am
by nevon
I think you're talking about require.

Re: Loading another script

Posted: Sat Dec 31, 2011 6:22 pm
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

Re: Loading another script

Posted: Sat Dec 31, 2011 6:48 pm
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 ...

Re: Loading another script

Posted: Sat Dec 31, 2011 7:15 pm
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.

Re: Loading another script

Posted: Sat Dec 31, 2011 8:02 pm
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?

Re: Loading another script

Posted: Mon Jan 02, 2012 2:49 pm
by Robin
What is your question?

Re: Loading another script

Posted: Thu Jan 05, 2012 3:11 am
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

Re: Loading another script

Posted: Thu Jan 05, 2012 3:50 am
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.

Re: Loading another script

Posted: Thu Jan 05, 2012 6:32 am
by yarickyarick
I did not understand a bit and then n * n, VarB and the like ...