Decrease the value of timer.performWithDelay(1000

Hello again,
I’m a bit confused now… you want a timer to fire 800 times in a 10 second span (10000)? I assume you want them to fire “faster” as they go, not just every 12.5 milliseconds (10000 / 800)? [import]uid: 200026 topic_id: 36154 reply_id: 143623[/import]

I do want it to fire 800 times (take -1 of the total, 800times) whit a brake of 10 seconds between the -1. so:

1000 -1 = 999 (wait 10 seconds) 999 - 1 = 998 (wait 10 seconds)… til its at 200 [import]uid: 225288 topic_id: 36154 reply_id: 143625[/import]

yes but how can i add a performWithDelay so it fires 800 every 10000, i have tried this now

local timerTime = 1000 local function manageTimer() local function getRandomStar() print(timerTime) if ( timerTime \>= 500 ) then manageTimer() ; timerTime = timerTime-1 end end starTimer1 = timer.performWithDelay( timerTime, getRandomStar, 0 ) end manageTimer() timer2.performWithDelay(10000, manageTimer, 800) [import]uid: 225288 topic_id: 36154 reply_id: 143620[/import]

Like this?

[code]

local function myFunction( event )
if event.count >= 800 then
timer.cancel( event.source )
end

print( “I have executed:”, event.count, " times." )
end

local myTimer = timer.performWithDelay( 1000, myFunction, 0 )
[/code] [import]uid: 84637 topic_id: 36154 reply_id: 143639[/import]

Hi Danny,

yes that works but how can i combine the 2 codes, i have tried :

local function myFunction( event )  
 if event.count \>= 800 then  
 timer.cancel( event.source )  
 end  
   
local timerTime = 1000  
   
local function manageTimer()  
 local function getRandomStar()  
 print(timerTime)  
 if ( timerTime \>= 200 ) then manageTimer() ; timerTime = timerTime-50 end  
 end  
 starTimer1 = timer.performWithDelay( timerTime, getRandomStar, 1 )  
end  
manageTimer()  
  
 print( "I have executed:", event.count, " times." )  
end  
   
local myTimer = timer.performWithDelay( 1000, myFunction, 0 )  

&

local timerTime = 1000  
  
local function myFunction( event )  
 if event.count \>= 800 then  
 timer.cancel( event.source )  
 end  
   
 print( "I have executed:", event.count, " times." )  
  
local function manageTimer()  
 local function getRandomStar()  
 print(timerTime)  
 if ( timerTime \>= 200 ) then manageTimer() ; timerTime = timerTime-50 end  
 end  
 starTimer1 = timer.performWithDelay( timerTime, getRandomStar, 1 )  
end  
  
end  
   
local myTimer = timer.performWithDelay( 1000, myFunction, 0 )  
  
manageTimer()  

But both don’t work ? [import]uid: 225288 topic_id: 36154 reply_id: 143751[/import]

OK, then how about this?

[code]
local timerTime = 1000

local function getRandomStar()
–do something!
end

local function countdownTimer()
timer.performWithDelay( timerTime, getRandomStar, 1 )
timerTime = timerTime-1
end

countdownTimer() --call countdownTimer immediately on start (one time)
–now let timer handle it 800 times
local mainTimer = timer.performWithDelay( 10000, countdownTimer, 800 )
[/code] [import]uid: 200026 topic_id: 36154 reply_id: 143766[/import]

Yes this works for me!

local timerTime1 = 1000  
local function countdownTimer()  
 starTimer1 = timer.performWithDelay( timerTime1, getRandomStar, 0 )  
 timerTime1 = timerTime1-1  
 print("time1 " .. timerTime1)  
end  
countdownTimer()  
local mainTimer = timer.performWithDelay( 10000, countdownTimer, 800 )  

I need to send you guys a chocolate cake or something when the game is finished, the support is amazing! [import]uid: 225288 topic_id: 36154 reply_id: 143819[/import]

I know you resolved this but my curiosity just has to ask. Why are you doing -1 every 10 seconds? That 1 is just a millisecond. Therefor it would take 16 minutes (1000 seconds) to shave off 100 milliseconds. Is it a space/star viewing realistic app? Sorry for the weird question, feel free to ignore it. Best of luck with your app! [import]uid: 77199 topic_id: 36154 reply_id: 143866[/import]

Hello @mmk.verheijden,
If I understand, you want the timer to fire 800 times, and each time, the duration is 1 millisecond less? As follows?

1000, 999, 998, 997, 996, …

If so, one method would be this:

[code]
local timerTime = 1000

local function manageTimer()
local function getRandomStar()
print(timerTime)
if ( timerTime >= 200 ) then manageTimer() ; timerTime = timerTime-50 end
end
starTimer1 = timer.performWithDelay( timerTime, getRandomStar, 1 )
end
manageTimer()
[/code] [import]uid: 200026 topic_id: 36154 reply_id: 143619[/import]

Hello again,
I’m a bit confused now… you want a timer to fire 800 times in a 10 second span (10000)? I assume you want them to fire “faster” as they go, not just every 12.5 milliseconds (10000 / 800)? [import]uid: 200026 topic_id: 36154 reply_id: 143623[/import]

I do want it to fire 800 times (take -1 of the total, 800times) whit a brake of 10 seconds between the -1. so:

1000 -1 = 999 (wait 10 seconds) 999 - 1 = 998 (wait 10 seconds)… til its at 200 [import]uid: 225288 topic_id: 36154 reply_id: 143625[/import]

yes but how can i add a performWithDelay so it fires 800 every 10000, i have tried this now

local timerTime = 1000 local function manageTimer() local function getRandomStar() print(timerTime) if ( timerTime \>= 500 ) then manageTimer() ; timerTime = timerTime-1 end end starTimer1 = timer.performWithDelay( timerTime, getRandomStar, 0 ) end manageTimer() timer2.performWithDelay(10000, manageTimer, 800) [import]uid: 225288 topic_id: 36154 reply_id: 143620[/import]

Like this?

[code]

local function myFunction( event )
if event.count >= 800 then
timer.cancel( event.source )
end

print( “I have executed:”, event.count, " times." )
end

local myTimer = timer.performWithDelay( 1000, myFunction, 0 )
[/code] [import]uid: 84637 topic_id: 36154 reply_id: 143639[/import]

Hi Danny,

yes that works but how can i combine the 2 codes, i have tried :

local function myFunction( event )  
 if event.count \>= 800 then  
 timer.cancel( event.source )  
 end  
   
local timerTime = 1000  
   
local function manageTimer()  
 local function getRandomStar()  
 print(timerTime)  
 if ( timerTime \>= 200 ) then manageTimer() ; timerTime = timerTime-50 end  
 end  
 starTimer1 = timer.performWithDelay( timerTime, getRandomStar, 1 )  
end  
manageTimer()  
  
 print( "I have executed:", event.count, " times." )  
end  
   
local myTimer = timer.performWithDelay( 1000, myFunction, 0 )  

&

local timerTime = 1000  
  
local function myFunction( event )  
 if event.count \>= 800 then  
 timer.cancel( event.source )  
 end  
   
 print( "I have executed:", event.count, " times." )  
  
local function manageTimer()  
 local function getRandomStar()  
 print(timerTime)  
 if ( timerTime \>= 200 ) then manageTimer() ; timerTime = timerTime-50 end  
 end  
 starTimer1 = timer.performWithDelay( timerTime, getRandomStar, 1 )  
end  
  
end  
   
local myTimer = timer.performWithDelay( 1000, myFunction, 0 )  
  
manageTimer()  

But both don’t work ? [import]uid: 225288 topic_id: 36154 reply_id: 143751[/import]

OK, then how about this?

[code]
local timerTime = 1000

local function getRandomStar()
–do something!
end

local function countdownTimer()
timer.performWithDelay( timerTime, getRandomStar, 1 )
timerTime = timerTime-1
end

countdownTimer() --call countdownTimer immediately on start (one time)
–now let timer handle it 800 times
local mainTimer = timer.performWithDelay( 10000, countdownTimer, 800 )
[/code] [import]uid: 200026 topic_id: 36154 reply_id: 143766[/import]

Yes this works for me!

local timerTime1 = 1000  
local function countdownTimer()  
 starTimer1 = timer.performWithDelay( timerTime1, getRandomStar, 0 )  
 timerTime1 = timerTime1-1  
 print("time1 " .. timerTime1)  
end  
countdownTimer()  
local mainTimer = timer.performWithDelay( 10000, countdownTimer, 800 )  

I need to send you guys a chocolate cake or something when the game is finished, the support is amazing! [import]uid: 225288 topic_id: 36154 reply_id: 143819[/import]

I know you resolved this but my curiosity just has to ask. Why are you doing -1 every 10 seconds? That 1 is just a millisecond. Therefor it would take 16 minutes (1000 seconds) to shave off 100 milliseconds. Is it a space/star viewing realistic app? Sorry for the weird question, feel free to ignore it. Best of luck with your app! [import]uid: 77199 topic_id: 36154 reply_id: 143866[/import]