Thread Tools Display Modes
04-29-20, 05:38 AM   #1
Ulverbeast
A Defias Bandit
Join Date: Apr 2020
Posts: 2
WeakAuras 2 button with macro

Hi all

I'm trying to program a button to run a simple macro with a /script command, but it doesn't work. The code works if I just set the macrotext to "/sit". I will post two examples to show what I mean

Example 1:
f.button = CreateFrame("Button", nil, f,"SecureActionButtonTemplate")
f.button:SetAttribute("type","macro")
local macrotext = "/sit"
f.button:SetAttribute("macrotext",macrotext)

Example 2:
f.button = CreateFrame("Button", nil, f,"SecureActionButtonTemplate")
f.button:SetAttribute("type","macro")
local macrotext = "/script SetLootMethod("group")"
f.button:SetAttribute("macrotext",macrotext)

In this case, example 1 works fine, but example 2 does not change to group loot, even though the macro text works if I save it as a macro and run it. Is this due to some limitation in the API? And is there any other way to program the button to perform this action without setting the type as macro if so?

Thanks for any help
  Reply With Quote
04-29-20, 06:56 AM   #2
Urtgard
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 25
Enable Lua errors:
Code:
/console scriptErrors 1
The second " indicates the end of macrotext.
Therfore in example 2 your macrotext is cut off.

If you want to use special characters inside a string you must escape them.
Code:
local macrotext = "/script SetLootMethod(\"group\")"
  Reply With Quote
04-30-20, 07:04 AM   #3
Ulverbeast
A Defias Bandit
Join Date: Apr 2020
Posts: 2
Thanks very much for the help, I tried it out and everything seems to work now
  Reply With Quote
04-30-20, 11:18 AM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Or you can use single apostrophes.
Lua Code:
  1. "macro text with a 'string' inside"


-----------
(Example of what Urtgard was telling you
Lua Code:
  1. "macro text with a "string" inside"
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » WeakAuras 2 button with macro

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