View Single Post
Old 12-18-2019, 09:58 AM   #644
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by reapero View Post
Because the menubox preset selector is inside the main loop
I'm confused; why is the preset selector in your main loop? You should just have to attach your handler to the menubox so it's run every time the user chooses a preset. Something like:
Code:
local function updateOtherElements()
  ...
end

function GUI.elms.myMenuBox:onmouseup()
  GUI.Menubox.onmouseup(self)

  updateOtherElements()
end

function GUI.elms.myMenuBox.onmouseup()
  GUI.Menubox.onwheel(self)

  updateOtherElements()
end
Quote:
So, if i want to keep it simple with just the menubox, is there a way to call a function from the loop but only once? Ideally updating the GUI with the preset data should happen only when the menubox selector changes, not on every loop.
If you do need to have it in the main loop, for whatever reason, then something like this will do the trick:
Code:
local presetWasChanged = false

function GUI.elms.myMenuBox:onmouseup()
  GUI.Menubox.onmouseup(self)
  presetWasChanged = true
end

function GUI.elms.myMenuBox.onmouseup()
  GUI.Menubox.onwheel(self)
  presetWasChanged = true
end

local function mainLoop()
  if presetWasChanged then
    -- Update the other elements
    presetWasChanged = false
  else
    -- Do something else
  end

  reaper.defer(mainLoop)
end

mainLoop()
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote