Update timer frequency while running(HALP)

So I want to make a timer go faster and faster to spawn objects more and more frequently

What I have now is



FYI
What I want is for the timer that triggers the spawner function to update its frequency(f) everytime it changes(changed by function time) so the spawner with start spawning slowly and then go faster and faster and faster

But once the timer is set it does not update the frequency
If I use the update and set the timer on false a timer will be initiated 60 times each secondso it doesnt work
If I use another timer to timer the timer the inner timer will only play when the other timer does and The outer timer still wont update the frequency

So Im out of ideas helpp

Anyone

If this is the way the code is written, then it can’t work because lua is case sensitive. “Frequency” is a different variable from “frequency”.

Can you please fix the formatting. It’s hard to tell what’s what.

Oh no no I was just typing really fast It is correct in the script

Fixed

I’m still struggling to understand. I have a few questions and comments:

  • You use global functions and variables. time() and spawner() are both global (there is no local keyword in front of them). t and f are also global.
    • If you have the same variables and functions declared in some other script you will for sure run into problems.

What is this supposed to do:

if f ~= 0.001 then
    f = f
end

I don’t see f modified anywhere.

I’m also confused by the use of two timers.

timer.delay(1, true, time)
timer.delay(f, true, spawner)

The purpose of the 1 second timer calling into time() seems to be to decrease t by 5 every second. (and do something/nothing with f).
The purpose of the 2 second (f) timer calling into spawner() seems to be to depending on the value of t post one out of a several messages to spawn something.

What is not working? Did you expect the timer for spawner() to be called more and more frequently? It will never do that since it started in init() with a 2 second interval. Modifying f afterwards will not change the timer. You need to stop and restart the timer with a new value to f for that to happen.

1 Like

Sorry I cant do code font iphone just wont add a backwards ‘ for the code font style

Oh fricking frick what the hell the f was suppose to be f=fx0.95
Can I ask how does timers work
Does it start off by wait for the time after jt is called then do the function or does it do the function then wait for the time

WAIT WAIT CAN I make it so there will be a third function called repeater, i remove the f from timer function and so first I ativate the timer calling the spawn once with false for repeat then at the end of the spawn function I add a link to activate the repeater function and the repeater function will be this

Function repeater()
____F=1
____If f >0.1 then
_________F=f*0.95
____End
____Timer.delay(f,false,spawn)
End

Will thus form a loop and so the time updates omg im a genius

Also I dont understand the timer.stop function it goes like putting timer.stop() in the function that has timer.delay but when I load it it says expect variable in () so I just left a random 2 in the timer.stop(2) and it worked what is the () suppose to be for WHATS HANDLE

Also whats this weird banner icon next to the report button that seems to not do anything when I click

f ~= 0.001

Also, I’d advice against doing such equality checks for floating point numbers.
I’d suggest using either “<”, “>”. More info here.

2 Likes

Hmm okay

Here’s what I would do:

local function next_bullet(self)
	-- if we already have a timer firing bullets we need to cancel it
	-- we also change to the next type of bullet to fire
	if self.fire_timer then
		timer.cancel(self.fire_timer)
		self.bullet_type = math.min(self.bullet_type + 1, #self.bullets)
	end
	-- get the bullet to fire
	local bullet = self.bullets[self.bullet_type]
	-- start a timer to call the bullet fire() function with the defined
	-- interval
	self.fire_timer = timer.delay(bullet.frequency, true, bullet.fire)
end

function init(self)
	-- definition of bullets to fire
	self.bullets = {
		{
			frequency = 2,
			fire = function() msg.post("/bullet_sender#bullet_sender", "wb") end,
		},
		{
			frequency = 1.9,
			fire = function() msg.post("/bullet_sender#bullet_sender", "db") end,
		},
		{
			frequency = 1.8,
			fire = function() msg.post("/bullet_sender#bullet_sender", "sb") end,
		},
	}

	-- start with the first bullet type
	self.bullet_type = 1
	-- start firing the bullet
	next_bullet(self)
	-- start a timer that every 30 seconds will change to the next bullet
	timer.delay(30, true, next_bullet)
end
2 Likes

Woah okay