View Single Post
Old 05-31-2019, 09:26 AM   #498
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,241
Default

GUI.func is just a top-level thing. Components don't have any built-in frequency settings for onupdate, but you could keep them from all updating at the same time with something like:
Code:
-- When creating them, assign a random number from 0 to 99
myElement.updateIndex = Math.floor(Math.random() * 100)

function myElement:onupdate()
  if elementUpdateCounter == self.updateIndex then
    -- update stuff
  end
end

-- Increment a global counter
GUI.func = function()
  elementUpdateCounter = (elementUpdateCounter + 1) % 100
end
You might also look into Lua's "coroutines" - they're functions that you can effectively pause and come back to, which makes them great for saying "here's a giant pile of work, do a bit of it and then wait for the next script update to do a bit more". If your elements were named consistently but with increasing numbers, you could have a coroutine looping over all of them but only doing ten at a time, etc.
Lokasenna is offline   Reply With Quote