Macro syntax linter or general debugging tips?

Are there any options for debugging macro lua, or any syntax linters for testing syntax?

Here’s the situation. I wanted to create a macro that would toggle an action bar.

The code I started with was :

/run abv=MultiBar6:GetAlpha() if abv==1 then MultiBar6:SetScale(0.01);else MultiBar6:SetScale(1); MultiBar6.SetAlpha(1-abv)

I spent hours trying to figure out why this wouldn’t work.

The first problem was a missing end. And the second problem was using . instead of : for the SetAlpha() command.

Final working macro is (newlines/spacing added for readability):

/run abv=MultiBar6:GetAlpha() 
if abv==1 
then 
  MultiBar6:SetScale(0.01);
else 
  MultiBar6:SetScale(1);
end 
MultiBar6:SetAlpha(1-abv)

In trying to debug, I tried using /dump and /etrace, but those weren’t what I was looking for.

Any useful debugging tips from the community?

For one thing, all your variables should be local so they don’t cause issues with the global namespace.

BugSack and BugGrabber are the two main tools people use.

/run local abv=MultiBar6:GetAlpha() if abv==1 then MultiBar6:SetScale(0.01);else MultiBar6:SetScale(1); MultiBar6.SetAlpha(1-abv)
1 Like

You might give the WowLua addon a try; it’s an in-game text editor with Lua syntax highlighting, so it’s handy for finding missing keywords and suchlike.

Side note:

That’s not actually incorrect syntax in the general case (the “:” call is syntactic sugar), so there’s nothing that a general linter or other syntax checker could do. (A WoW-specific checker with knowledge of the SetAlpha() function would be needed, which is not impossible but I’ve no idea if anybody has written one.)

1 Like

I had local at some point in the iteration. Thanks for calling it out! I’ll add it back in.

Those look promising. I’ll check them out, thanks!

This also looks good. Thanks! On the syntax highlighting, I’m noticing that the forum highlighter can show the difference.