Macro/Add-On For Toggling Custom CVar Values

I’m looking for a macro (or small add-on, if necessary) to toggle between two or more states of a CVar that accepts a range of values, not just an on/off toggle.

For example, groundEffectDist is a CVar that accepts any value between 40 and 500, and I’d like to be able to cycle through a few different values that I define, with the repeated press of a button. I would also prefer that, once reaching the final entry, the code loops back around to the initial value and continues to move between each entry while the button continues to be pressed.

If the above example is confusing, here’s a visual example using the same CVar along with three values: 100, 200, and 300.

Button Press |  CVar Value
     1st     |     100
     2nd     |     200
     3rd     |     300
     4th     |     100 <-- Loops back around
     5th     |     200

Finally, I assume that the required code may exceed the in-game macro character limit, especially if there are many values I’d like to toggle between, so that’s why I mentioned a small add-on.

Any assistance is appreciated - Thanks!

A macro to cycle a cvar from 100, 200 and 300 is fairly simple, assuming it’s one of those values already:

/run local c="groundEffectDist" SetCVar(c,GetCVar(c)%300+100) print(c,"now",GetCVar(c))

But you probably want something more generic. This macro will cycle through values in the table and also set the cvar if it was a value not in the table:

/run local c,t="groundEffectDist",{"100","200","300"} for i=1,#t do if GetCVar(c)==t[i] then SetCVar(c,t[i+1] or t[1]) break elseif i==#t then SetCVar(c,t[1]) end end print(c,"now",GetCVar(c))

Note the double quotes there. cvars are actually strings so if you do {100,200,300} it will never match one of them and you’d get 100 over and over.

3 Likes

Yes, the second example is perfect and is working wonderfully. Now, I can just plug in whatever CVars and values I’d like to test and/or demonstrate with.

Thanks for the assistance! :+1:

Hey Gello do you know how I could remove the default health bar texture in 10.5?
I was using

PlayerFrame.PlayerFrameContent.PlayerFrameContentMain.HealthBarArea.HealthBar:DisableDrawLayer("ARTWORK")

But since 10.5 came out that line of code doesn’t work anymore and now shows up next to the spinner frames that I’m using for player and target. :stuck_out_tongue: