Thread Tools Display Modes
07-19-18, 02:02 PM   #1
eoblaed
A Murloc Raider
 
eoblaed's Avatar
Join Date: Jul 2018
Posts: 7
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!
  Reply With Quote
07-19-18, 02:09 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
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.
  Reply With Quote
07-19-18, 02:30 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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()
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
07-19-18, 03:37 PM   #4
eoblaed
A Murloc Raider
 
eoblaed's Avatar
Join Date: Jul 2018
Posts: 7
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!
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Add New Code in New File to Existing Addon

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off