Thread: Basic Questions
View Single Post
01/02/18, 05:43 PM   #4
Ni Lucian
Join Date: Jan 2018
Posts: 7
That helps a lot thank you. So, to answer your question my background is Java HEAVY. I have experience with C#, MYSQL, and some top level browser stuff.

So, my only left over question then is.

Code:
EVENT_MANAGER:RegisterForEvent(Nilucian.name, EVENT_LEADER_UPDATE, Nilucian.runIt)
Is that a function I am referencing then? In that case you can make calls to functions outside of any function? Or to relate it to Java; you can execute code outside of a method or construct and just have code executed within the class itself? Does this mean I could theoretically use d() outside of a function and somehow it will be called? If I was going to make this question concise I would say: when/where is control (or a thread) passed to my files? Is there some main function?



Second, about packages. I suggest reading about scope in Lua, if you haven't already. Functions in another file can only be accessed if they are global, or in a global table. If you use local when you create it and do not later assign it to a global variable name you will be unable to use it. Its similar to private and public functions in OOP. There's no need to say import file or load package or whatever. It'll be loaded and available anyway.
So, I have read on scope and it doesn't seem to foreign, but how do I reference a global variable form another file? It seems like- if I am understanding you correctly- you only have to declare a global variable and it is then accessible by all files? In that case if you were re-assigning that variable in one file it would effect how all other files receive it? Essentially a public static variable in java only it can be of any type.



Your txt file determines this, with the files loaded in the order they are listed.

For example: a lot of us use libraries in a lib folder. So if you want to use lib\whatever\whatever.lua, you'd put in your txt file:

lib\whatever\whatever.lua
your_addon.lua

Then your addon can properly call the variables in that other file.
Does this mean I have to load my files in such an order that each file only references files after it in the compile or load order?
  Reply With Quote