Thread: Basic Questions
View Single Post
01/02/18, 06:52 PM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
It's hard to compare a compiled language like Java to a scripting language like Lua. It simply works differently. Since you don't seem to know Lua I suggest you start reading here and do a few tutorials.

In Lua you don't have to care about the concept like "inside or outside a method". What's more important is the concept of "closures". You can nest functions and then access variables outside of the inner function without having to pass the value to it (up to the global scope). Basically you are already in a file-local scope at the first line of a file and can put d() there (but it won't show anything since the chat is only initialized later).

In the beginning when the character is loaded all addons that are active will have their files loaded in the order they appear in the manifest.
Aside of this initial loading, you will always have to react to some type of event or user input - that's your entrance point for anything. Since you are single threaded, it will always call one callback after another and one line after another. You do not have to worry about anything happening in parallel.

Also datatypes do exist, but are not declared. You can just assign any type to any variable at any time or pass any value to any function (even if they do not use it). The only thing you should remember is that tables and userdata are pointers - assigning or passing them and changing something on the new variable will affect the original. All other datatypes are copied (although strings do use references internally to save memory).

You only have to care about the load order when you do stuff while files are being loaded (-> file scope). Once the EVENT_ADDON_LOADED has fired for your addon, you can be sure that all your files have loaded and just access the global variables you have created.
  Reply With Quote