Not sure what I'm looking for
Hi,
So I have an addon for quite some time now but it's getting a bit big and messy since it's all in 1 file. Now I want to split it up in different files (think classes in say C++) but I have absolutely no idea how to do it. I've tried searching for guides about it but I don't quite know what exactly I'm looking for, so I haven't found anything. To give an idea about the addon: It tracks different things related to battlegrounds (mainly randoms) such as your honor/conquest points, your kills/deaths in the current bg, your exp gained, .... Each one of those tracks is like its own class so to speak and i want to create a seperate file for them, rather than have all of them in 1 big spaghetti code. The main thing I'm looking for is something where I can just write a file and link it to the core myself. |
I would do it like this:
core.lua Lua Code:
module1.lua Lua Code:
module2.lua Lua Code:
|
So variables can just go cross ... file then ?
How would I go about calling a function from say module1 in core? Or can I just call them cross file as well like the variables as long as I don't make them local ? I guess there's isn't something like module1.function1() like you'd have in c Edit: just tested it and seems to work... can't believe it was that easy |
Quote:
Instead, use the private table Blizzard provides each and every addon for exactly this purpose. This table is not in the global namespace (though you can put it there if you want) and you can access it by adding a line like this to each of your files: Code:
local ADDON_NAME, addon_private_table = ... The first value in the file-level vararg (the three dots) is a string containing your addon's name. It's the same value that's passed with your addon's ADDON_LOADED event, and that you can pass to GetAddOnInfo and similar functions. The second value is a table. You can put whatever you want in it. It's only visible to the files in your addon, though you can make it global if you really want: Code:
local ADDON, private = ... |
Ok. That makes sense. I'll use it from now on. Thank you.
|
Well I'm currently switching to the different files and it's working out quite well so far.
I'm using a global table right now but I'll see if I can change it to the private version. If it fine to have functions in the global space though? For example my core file has a function to get your kills end some of the other files use that function. I add the addon name to the beginning of the variable names to lower the change of issues, but it's still a bit iffy. I might be able to just switch it to the files instead and have them local, but I'm just curious in case I run into something like it in the future. |
Quote:
Code:
-- File A Code:
-- File A |
Quote:
|
All times are GMT -6. The time now is 03:37 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI