How do I make an application that runs continuously

Since the clock sample does not actually work and just freezes after a short time I cannot make a functioning clock application - at least I don’t know how to.

Does anyone have a solution that they are using successfully to create a ‘run loop’ in their code.

See: http://developer.anscamobile.com/forum/2010/03/12/clock-sample-app-freezes
[import]uid: 846 topic_id: 1052 reply_id: 301052[/import]

Not sure about the clock sample problem, but this is all event-driven programming here.

You can easily create a timer which will fire off every n microseconds, then you just have that timer call your own handler to do what you need to do.

It’s sort of like a “run loop”, but it’s not just “do while(true)” kind of thing.

All of your interaction with the device is handled through events as well.

Hope that helps,
Scott [import]uid: 5659 topic_id: 1052 reply_id: 2583[/import]

Scott,

If you look at sample code posted (at the link) you will see there is a timer running but the problem is the timer stops firing after about an hour. This was logged as bug #139 at the end of April and appears not to be fixed.

I think this posting was asking if anyone had a work-around for this bug.

Tom [import]uid: 6119 topic_id: 1052 reply_id: 2584[/import]

That’s right. I’m looking for a workaround for the bug. [import]uid: 846 topic_id: 1052 reply_id: 2586[/import]

First thing I’d try is after X timer executions (say amounting to 5 minutes), I’d kill the current timer and start a new one.

That would at least show whether it was a problem with memory or a problem with the timer getting confused.

Scott [import]uid: 5659 topic_id: 1052 reply_id: 2587[/import]

I ran the sample counter code on my iPhone using Corona 2.0 beta 3 and the counter stopped counting at 2880, which is 12 minutes (timer fires every 0.250 seconds).

I modified the code as Scott suggested to cancel and restart the timer every 5 minutes and the counter still stops at 2880.

What’s magical about 12 minutes?

Tom [import]uid: 6119 topic_id: 1052 reply_id: 2594[/import]

That’s actually some pretty good intel for the Ansca team I’d imagine. If that didn’t work, I’m really not sure what would other than waiting for Ansca to come up with a fix (or once they know the problem, a workaround).

I’d suggest you post your modifications to the counter code on the bug thread so they have another test case for the bug.

Scott [import]uid: 5659 topic_id: 1052 reply_id: 2596[/import]

Here is some code that has been running over an hour on my 3GS iPhone. It uses “enterFrame” instead of a timer to update the counter. (The timer code stops counting after 2880 count – 12 minutes.)

-- Seconds Clock   
-- infinite timed count  
--  
-- Corona bug #139 - test code  
  
system.setIdleTimer( false ) -- turn off device sleeping  
  
local counter = 0  
local frameCount = 0  
local clockTimer  
  
local countField = display.newText( tostring(counter), 150, 190, "Arial-BoldMT", 48 )  
countField:setTextColor( 255, 255, 255 )  
  
local numField2 = display.newText( "v1.01", 10, 450, "Arial-BoldMT", 12 )  
numField2:setTextColor( 255, 255, 255 )  
  
-- This function is called for every frame  
-- Updates the on screen counter every second.  
--  
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
local function updateCount()  
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 frameCount = frameCount+1  
  
 -- Update counter every second (assuming 30 FPS)  
 if ((frameCount % 30) == 0) then  
 counter=counter+1  
 countField.text = tostring(counter)  
 print "Update"  
 end  
  
end -- updateCount  
  
Runtime:addEventListener( "enterFrame", updateCount )  
--clockTimer = timer.performWithDelay( 250, updateCount, 0 )  

Tom [import]uid: 6119 topic_id: 1052 reply_id: 2603[/import]

Escalating bug #139 [import]uid: 24 topic_id: 1052 reply_id: 2604[/import]

Hi all,

What if you avoid to use system.setIdleTimer at the very begin of your code? It does the same error?

Regards,

Flavio. [import]uid: 3022 topic_id: 1052 reply_id: 2610[/import]

Flavio,

No change if you comment out the “system.setIdleTimer” code. Timer still stops at count 2880.

Tom [import]uid: 6119 topic_id: 1052 reply_id: 2612[/import]

Thanks bunches for the workaround. I’ll give it a whirl. [import]uid: 846 topic_id: 1052 reply_id: 2732[/import]