Uknown Command
#11
MCServer loads and primes all .lua files that are in the plugin's folder, in alphabetical order, except for the Info.lua file which is always loaded as the last one. So anything you define globally in any file is accessible in any other file.
Reply
Thanks given by:
#12
(05-12-2015, 07:02 AM)xoft Wrote: MCServer loads and primes all .lua files that are in the plugin's folder, in alphabetical order, except for the Info.lua file which is always loaded as the last one. So anything you define globally in any file is accessible in any other file.

Does this mean that function order doesn't matter at all? For example
function cool()
  hi()
end

function hi()
  print("hi")
end
will work fine? In the environment I worked in, Lua files weren't "primed" in that sense and I had to actually pay attention to my function structure.
Reply
Thanks given by:
#13
(Found out this is not true)It really depends. When you call those functions from the global code in the file (code not wrapped within any function), it will not work. If you call the function as a reaction to something MCServer calls (such as the Initialize() method, or the hook handlers etc.), then it will work, because at that time the globals will be fully primed.

So, for example, this WON'T work:
function cool()
  hi()
end

function hi()
  print("hi")
end

function intermediate()
  cool()
end

-- Global call, fails:
intermediate()

You should not use this anyway, you should call any initialization in the Initialize() function and then react to callbacks from the server; only use global calls for trivial things, such as setting up global singletons etc.

(Use [ shcode=lua ] code [ /shcode ] in the forum to post Lua code)
Reply
Thanks given by:
#14
Hm, I've tried the code and it actually works.
Reply
Thanks given by:
#15
(05-12-2015, 07:22 AM)xoft Wrote: (Found out this is not true)It really depends. When you call those functions from the global code in the file (code not wrapped within any function), it will not work. If you call the function as a reaction to something MCServer calls (such as the Initialize() method, or the hook handlers etc.), then it will work, because at that time the globals will be fully primed.

So, for example, this WON'T work:
function cool()
  hi()
end

function hi()
  print("hi")
end

function intermediate()
  cool()
end

-- Global call, fails:
intermediate()

You should not use this anyway, you should call any initialization in the Initialize() function and then react to callbacks from the server; only use global calls for trivial things, such as setting up global singletons etc.

(Use [ shcode=lua ] code [ /shcode ] in the forum to post Lua code)

I never intended to use global calls. I had planned to use the Initialize function act as a "main" function then tie my code to continue after initialize. I was just more or less curious on the process that McServer does to load these files so I can figure out what I can and can't do. I'm a VERY in depth person so you'll probably be seeing tons of more questions from me on these forums.

I plan to provide MCServer a lot of support in return though. xP

Edit: So it does work? Interesting.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)