game = {updates = {}, running = false} function game:update () self.numupdates = 0 for i, v in pairs(self.updates) do self.numupdates = self.numupdates + 1 v(self) end end function game:run () self.isrunning = true repeat self:update() until self.numupdates == 0 self.isrunning = false end do local times = 10 function game.updates:test () print(times) times = times - 1 if times == 0 then game.updates.test = nil end end end game:run() --[[ 10 9 8 7 6 5 4 3 2 1 ]]