From 5c77e58ecd1971be99aae978779b636b65139db5 Mon Sep 17 00:00:00 2001 From: Leslie Krause Date: Sat, 16 May 2020 14:41:00 -0400 Subject: [PATCH] Build 17 - Closes #24 --- init.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index d60374a..adf81df 100644 --- a/init.lua +++ b/init.lua @@ -51,6 +51,7 @@ local rad_0 = 0 function Timekeeper( this ) local timer_defs = { } + local pending_timer_defs = { } local clock = 0.0 local delay = 0.0 local self = { } @@ -64,22 +65,30 @@ function Timekeeper( this ) end self.start = function ( period, name, func ) - timer_defs[ name ] = { cycles = 0, period = period, expiry = clock + delay + period, started = clock, func = func } + timer_defs[ name ] = nil + pending_timer_defs[ name ] = { cycles = 0, period = period, expiry = clock + delay + period, started = clock, func = func } end self.start_now = function ( period, name, func ) + timer_defs[ name ] = nil if not func( this, 0, period, 0.0, 0.0 ) then - timer_defs[ name ] = { cycles = 0, period = period, expiry = clock + period, started = clock, func = func } + pending_timer_defs[ name ] = { cycles = 0, period = period, expiry = clock + period, started = clock, func = func } end end self.clear = function ( name ) + pending_timer_defs[ name ] = nil timer_defs[ name ] = nil end self.on_step = function ( dtime ) clock = clock + dtime + for k, v in pairs( pending_timer_defs ) do + timer_defs[ k ] = v + pending_timer_defs[ k ] = nil + end + local timers = { } for k, v in pairs( timer_defs ) do if clock >= v.expiry and clock > v.started then @@ -679,7 +688,7 @@ mobs.register_mob = function ( name, def ) -- alertness and awareness functions -- - start_awareness = function ( self, target ) + start_awareness = function ( self ) local awareness = self.awareness_stages[ self.state ] if awareness then