0
votes

I'm changing something in an Addon for World of Warcraft which are written in Lua. There is a simple boolean variable which determines if some "all" frames are shown or only specific one.

So when = true then it will only show specific frames when = false it will show all frames

I want to make a modifier with the shift key to show all frames when the shiftkey is pressed and hide them again when shift is realeased.

if IsShiftKeyDown() then
    cfg.aura.onlyShowPlayer = false
else
    cfg.aura.onlyShowPlayer = true
end

This is my very simple solution for it which works. The problem here is though it only works on starting of the script. You see in WoW everytime the interface gets loaded it will run the script if not told otherwise. That is not very efficent because I would send my user into a loadingscreen.

OnUpdate should fix my problem here which will run this specific code everytime a frame gets rendered which is pretty handy and is what I want to accomplish.

So this is what I made

local function onUpdate(self,elapsed)
   if IsShiftKeyDown() then
     cfg.aura.onlyShowPlayer = false
   else
     cfg.aura.onlyShowPlayer = true
   end 
end

local shiftdebuffs = CreateFrame("frame")
shiftdebuffs:SetScript("OnUpdate", onUpdate)

My problem is now that it doesn't work. I new to the onUpdate stuff and only copy pasted it from another addon I did which worked fine. Right it goes straight to = false, which is only happening I think because it is the default.

thanks for the help

1

1 Answers

0
votes

Right it goes straight to = false, which is only happening I think because it is the default.

No, there is no "default" branch in the if statement. For the control to get to the then branch the condition has to be evaluated to true. You need to check the logic, but if the script executed cfg.aura.onlyShowPlayer = false, it means that IsShiftKeyDown() was evaluated as true.