WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Add New Code in New File to Existing Addon (https://www.wowinterface.com/forums/showthread.php?t=56392)

eoblaed 07-19-18 02:02 PM

Add New Code in New File to Existing Addon
 
I have several addons that still use the old GetMapNameByID() API call. This is now a 'nil'.

I wrote a thin wrapper function that looks up the old worldID, converts it to the new style UiMapID, and returns C_Map.GetMapInfo(newid).name. The code works when I embed it directly into the various .lua files of the addon (but, that's not a great solution).

What I'm trying to do is create a new file, MapCompat.lua, in such a way that will allow the other pre-existing lua files in the addon to see the GetMapNameByID() call in that new .lua file.

Not having authored an addon before, there's a seemingly labyrinthine combination of .xml, .toc, etc, and I haven't quite hit on the right combination of things to do what I want to do.

Any pointers?

Thanks!

Kanegasi 07-19-18 02:09 PM

No need to change or mess with any addons. If what you have works, just make a separate addon with the code and all addons will see it. You may have to name the addon with a ! in front to make sure it loads first. Those functions are global objects, so addons will see your change.

To make it even simpler, go to https://addon.bool.no, paste your code, and unzip it like any other addon.

Fizzlemizz 07-19-18 02:30 PM

Also, for future reference, if you want to pass information between modules (.lua files) within the same addon, each .lua file is "passed" two parameters, the name of the addon and a table that is exlcusive to that addon.

To use them, at the top of each file add

Code:

local addonName, addonTable = ...
the names can be anything you like.

You can create a function
Code:

function addonTable:GetMapNameByID()
    ...
end

Anywhere within your addon .lua files you can now call:
Code:

addonTable:GetMapNameByID()

eoblaed 07-19-18 03:37 PM

Thanks for the responses!

I've got things working now with the 'make an addon with the functions I'd like to be global' approach. I wasn't aware the scoping was that permissive. It's working now, though. Thanks!


All times are GMT -6. The time now is 10:16 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI