Simple Macro but nil value as an addon

Hello, below is a macro that I recently used to make the zone map appear on my left corner. However, I need to click the macro on every login. Therefore, I used the website addon.bool.no to turn it into a small addon. But, BugSack says that "attempt to index global ‘BattlefieldMapFrame’ (A nil value). I am unsure how to fix it. Thanks for any help!

/run BattlefieldMapFrame:ClearAllPoints();BattlefieldMapFrame:SetPoint("LEFT", 0,-300)
/run BattlefieldMapFrame:SetScale(1.38)
/run BattlefieldMapFrame.BorderFrame.CloseButton:Hide();

The addon contains

BattlefieldMapFrame:ClearAllPoints();BattlefieldMapFrame:SetPoint("LEFT", 0,-300)
BattlefieldMapFrame:SetScale(1.38)
BattlefieldMapFrame.BorderFrame.CloseButton:Hide();

The BattleField Minimap is an addon that is marked as Load On Demand so you need to load it before making any changes.

BattlefieldMap_LoadUI()
BattlefieldMapFrame:ClearAllPoints()
BattlefieldMapFrame:SetPoint("LEFT", 0,-300)
BattlefieldMapFrame:SetScale(1.38)
BattlefieldMapFrame.BorderFrame.CloseButton:Hide()

Edit: Probably a better alternative would be to leave the code as it was and add the following to your .toc file

## LoadOnDemand: 1
## LoadWith: Blizzard_BattlefieldMap

So the changes only occure if you use the battlefield map.

Both options left for future reference.

2 Likes

Thank you so much for the help! Would you mind if I ask, where could I find resources on these coding stuff? I attempted to fix this by myself after almost an hour but could not find much.

You can export the Blizzard UI from the game. I quick look at the Blizzard_BattlefieldMap.toc file showed it is LOD.

https://wow.gamepedia.com/Viewing_Blizzard%27s_interface_code
1 Like

Much appreciated!

This is likely irrelevant now, though I thought I’d throw this out there:

BattlefieldMap_LoadUI()
BattlefieldMapTab:ClearAllPoints()
BattlefieldMapTab:SetPoint(“LEFT”, 0, -250)
BattlefieldMapTab.SetPoint = function() end
BattlefieldMapFrame:ClearAllPoints()
BattlefieldMapFrame:SetPoint(“LEFT”, 0, -300)
BattlefieldMapFrame:SetScale(1.38)
BattlefieldMapFrame.BorderFrame.CloseButton:Hide()
BattlefieldMapFrame.BorderFrame.CloseButtonBorder:Hide()

This version hides the close button border, since the button is hidden anyway, giving it a cleaner look, and sets the zone map button on top as well in the event you need it.