Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

a timer for a for loop
Started by jepha.krampus Jan 29 2015 01:33 AM

- - - - -
5 replies to this topic
for loop timer delay

Best Answer davebollinger , 02 February 2015 - 08:41 AM

fe:

local loopy = {
  i=1,
  k=1,
  timer = function(self,event)
    print("i k =",self.i,self.k)
    self.k=self.k+1
    if (self.k>5) then
      self.i,self.k = self.i+1,1
      if (self.i>10) then
        timer.cancel(event.source)
      end
    end
  end
}
timer.performWithDelay(1000,loopy,-1)

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jepha.krampus

[GLOBAL: userInfoPane.html]
jepha.krampus
  • Observer

  • 13 posts
  • Corona SDK

hello!
i'm programming an app that contains a data structure like this one:

 

for i=1,10,1 do 
  print("i="..i)
  for k=1,5,1 do
    print("k="..k)
    if k==5 then
    print ("secondary loop ended")
  end
end
 
if i==10 then
print("primary loop ended")
 
end
 
now, what i want is that the program prints all the results with a delay time (for example, every second one of the results is printed)
 
is there any method, API or command able to do this???



thanks a lot

 

 


[TOPIC: post.html]
#2

endygwa

[GLOBAL: userInfoPane.html]
endygwa
  • Enthusiast

  • 41 posts
  • Corona SDK

Hi,

 

Do you want a 1 second delay between each iteration, or only delay the display of the results (all the results) by 1 second?

 

Thanks

endy



[TOPIC: post.html]
#3

jepha.krampus

[GLOBAL: userInfoPane.html]
jepha.krampus
  • Observer

  • 13 posts
  • Corona SDK

Hi,

 

Do you want a 1 second delay between each iteration, or only delay the display of the results (all the results) by 1 second?

 

Thanks

endy

 

hi,

 

i need a 1 sec delay between each iteration

thanks for your reply 

jepha



[TOPIC: post.html]
#4

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 982 posts
  • Corona SDK

Use timer.performWithDelay()

 

As parameters you can pass a function to execute, the time interval in milliseconds, and the number of times to repeat the function (including infinitely).



[TOPIC: post.html]
#5

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,373 posts
  • Corona SDK

  Best Answer

fe:

local loopy = {
  i=1,
  k=1,
  timer = function(self,event)
    print("i k =",self.i,self.k)
    self.k=self.k+1
    if (self.k>5) then
      self.i,self.k = self.i+1,1
      if (self.i>10) then
        timer.cancel(event.source)
      end
    end
  end
}
timer.performWithDelay(1000,loopy,-1)



[TOPIC: post.html]
#6

jepha.krampus

[GLOBAL: userInfoPane.html]
jepha.krampus
  • Observer

  • 13 posts
  • Corona SDK

thanks davebollinger, perfect answer!!! and of course thanks also to everyone who wanted to help me




[topic_controls]
[/topic_controls]