Doing a build while simulator is running and there are timers active crashes dmengine.exe, if you close the running simulator and build there is no crash. Now I know the timers need housekeeping and all that but should re-building be crashing dmengine.exe or is it a bug?
I have 2 timers repeating, 2 and 6 seconds. There appears to be triggering drift the longer the timers run.
timer.lua module:
Including timer.lua locally in multiple game objects seems to cause the timer script to interfere with the timers in the other game object when including a second instance of the same script. I could be flat out missing something here but even though it’s the same script file, they have different URL’s. Should they interfere with each other?
Native timer module (First two columns of dots):
Column 1 - spawned every 2 seconds
Column 2 - spawned ever 6 seconds
Dots are simply gravity falling from a factory using the same prototype, notice the time drift. After about 20 seconds you can see the drift as they spawn.
timer.lua module:
Column 3 - spawned every 2 seconds
Column 4 - spawned ever 6 seconds
The two scripts just seem to be cross spawning in the other GO with no apparent pattern.
No luck with this, changed both the native timer and timer.lua scripts so they use self:
local function spawnChild(self)
local childId = factory.create('#factory', nil, nil, {velocityX = self.velocityX, flame = self.flame}, 1)
table.insert(self.childIds, childId)
local timerId = timer.seconds(self.frequency, function()
spawnChild(self)
end)
table.insert(self.timerIds, timerId)
end
local function start(self)
spawnChild(self)
end
function init(self)
-- Add initialization code here
-- Remove this function if not needed
self.childIds = {}
self.timerIds = {}
start(self)
end
Ah, I see now. That old timer.lua module is like a singleton. It’s a single instance and list of timers, shared between all users. So when you call timer.update(dt) from multiple scripts the timer will count down faster than it should (it’s not dependant on real time but based on the dt values you pass in). You could adapt it so that you get one timer instance per script, but that’s not how it was designed. If you wish to use timer.lua, then I’d recommend that you call timer.update() only from a single place (perhaps a separate timer.script).