WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Multiple line macros using the macrotext attribute of a SecureActionButtonTemplate? (https://www.wowinterface.com/forums/showthread.php?t=57007)

Nightness 02-02-19 12:14 AM

Multiple line macros using the macrotext attribute of a SecureActionButtonTemplate?
 
I'm looking to make a multi-line macro (and have it work) in my MagnetButtons addon, that uses SecureActionButtonTemplate. I would rather not do what addons like VuhDo do and create actual character macros to do multi-line macros (I assume that's why they are there). Is there any way to have multiple macro calls in a single macrotext attribute?

Edit: What format do I use for newlines, that works in this case?

/cleartarget
/stopcasting
/script ToggleGameMenu(); StaticPopup1:Hide()

kurapica.igas 02-02-19 07:23 AM

Just use the '\n' between each lines.

Nightness 02-02-19 08:28 AM

Quote:

Originally Posted by kurapica.igas (Post 331505)
Just use the '\n' between each lines.

Tried '\n', and "|n", and \013\010 already.

Fizzlemizz 02-02-19 10:13 AM

Do you mean something like:
Lua Code:
  1. local button = CreateFrame('Button', 'ExitButton', nil, "InsecureActionButtonTemplate, UIPanelButtonTemplate")
  2. button:SetText("Logout")
  3. button:SetAttribute('type', 'macro')
  4. button:SetPoint("CENTER")
  5. button:SetSize(60, 24)
  6. SLASH_MCR1 = "/mcr"
  7. SlashCmdList["MCR"] = function(msg)
  8.     button:SetAttribute('macrotext', string.gsub(msg, '\92n', '\n'))
  9.     print(button:GetAttribute('macrotext'))
  10. end

Slash:
Code:

/mcr /cleartarget\n/stopcasting\n/script ToggleGameMenu(); StaticPopup1:Hide()
I might not be understanding properly what you are trying to achieve.

Vrul 02-02-19 04:21 PM

As mentioned "\n" will work:
Code:

local macrotext = "/cleartarget\n/stopcasting\n/script ToggleGameMenu(); StaticPopup1:Hide()"
or you could use a literal string:
Code:

local macrotext =
[[/cleartarget
/stopcasting
/script ToggleGameMenu(); StaticPopup1:Hide()]]

Keep in mind that you cannot have any spaces in front of a slash command's slash or it won't work. To get around that you can use:
Code:

local addonName = ...

local function CreateMacro(name, macrotext)
        name = ("%sMacro-%s"):format(addonName, name)
        local frame = _G[name]
        if not frame then
                frame = CreateFrame('Button', name, nil, 'SecureActionButtonTemplate')
                frame:SetAttribute('type', 'macro')
        end
        frame:SetAttribute('macrotext', macrotext:trim():gsub("%s+", " "):gsub(" /", "\n/"))
        return name
end

CreateMacro("Menu", [[
        /cleartarget
        /stopcasting
        /script ToggleGameMenu(); StaticPopup1:Hide()
]])

If "\n" didn't work then you have something else working against you so post your code.

Nightness 02-02-19 09:12 PM

Quote:

Originally Posted by Fizzlemizz (Post 331509)
Do you mean something like:
Lua Code:
  1. local button = CreateFrame('Button', 'ExitButton', nil, "InsecureActionButtonTemplate, UIPanelButtonTemplate")
  2. button:SetText("Logout")
  3. button:SetAttribute('type', 'macro')
  4. button:SetPoint("CENTER")
  5. button:SetSize(60, 24)
  6. SLASH_MCR1 = "/mcr"
  7. SlashCmdList["MCR"] = function(msg)
  8.     button:SetAttribute('macrotext', string.gsub(msg, '\92n', '\n'))
  9.     print(button:GetAttribute('macrotext'))
  10. end

Slash:
Code:

/mcr /cleartarget\n/stopcasting\n/script ToggleGameMenu(); StaticPopup1:Hide()
I might not be understanding properly what you are trying to achieve.

The gsub worked perfectly, thanks!!! :banana:


All times are GMT -6. The time now is 01:08 PM.

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