I’ve messed around with the timer.delay() function as i would like for a subroutine to wait for 3 seconds and then update a variable. The reason i’m doing this is to give my player a small period of invincibility so that the player can only lose 1 life every 3 seconds.
looking at the manual i think i need to use the function.
would i be correct in saying that this will automatically create a timer without any extra code required.
Also i understand the delay will be the number of seconds in the delay (for me this will be 3), repeat will be set to false because i only want to run this timer when the subroutine is called, But what is the callback for?
below is how i thought the code should be implimented but it must be incorrect because i’m getting an error becasue delay is set to a nil value?
local function update_damage(self, handle, time_elapsed) self.enemy_damage = false end local function player_damage(self, normal, distance) self.enemy_contact = true msg.post("player#player_hit", "play_sound") msg.post("/health#health", "remove_life") timer.delay(3, false, update_damage(self, handle, time_elapsed)) end
I’ve tried a few different things and looked at online videos but can’t seem to understand how it works. Can anyone tell me how the timer.delay() function works?