Screen refresh and unnecessary CPU/battery spending

Hi all. As I understand, Corona runs the whole script every frame (for example 30 fps). Let say I want to create a line on the screen. Fine. Created. I see the line on the screen. Is this line created every frame? And spends CPU cycles and battery to calculate coordinates etc? Can I first run some check to know: is there this line already exists? If yes, go to next operation. Let say I create a line at the very first frame after app started. I write an information about this fact into external file? Into global variable? So, at the second frame I can check the fact of line creation somewhere outside the script. Related topics: scope, global variables? I hope it is not a stupid question, but I am confused.

While Corona may have to render each frame, it does so in a very efficient way.  For instance, lines, shapes and images are only created when your code says to.  If things move, Corona positions them and re-renders the frame buffer.  This is how video works on devices. 

As far as global, local, scope, you have to apply best practices when coding.  Globals are supported, but they are not wise to use.  there are other techniques to use to have variables accessible in multiple modules.  Scope is very important because Corona is in effect a one-pass compiler, so if you declare something local after you try and use it, it will be nil or whatever global value the variable has.

A good read on Globals is:  http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Rob

Thank you Rob. When does screen refresh (or part of screen?) happen? When line properties change? And another question: if I need to calculate something long like weather model, for example 10 minutes of calculations. Is this possible? Or Corona is strictly screen-tied machine? I can’t understand the screen refresh and how/when it happens. I have read tutorials and guides by usual order and stands somewhere in the 1/3 of the whole documentation. I write code and it works. But I can’t understand above points.

This is one of those things you simply don’t need to worry about.   Corona updates the screen either 30 or 60 times per second.  If you need a long calculation, when its done, you make whatever drawing calls you need and Corona will take care of the rest.

Thank you Rob.

While Corona may have to render each frame, it does so in a very efficient way.  For instance, lines, shapes and images are only created when your code says to.  If things move, Corona positions them and re-renders the frame buffer.  This is how video works on devices. 

As far as global, local, scope, you have to apply best practices when coding.  Globals are supported, but they are not wise to use.  there are other techniques to use to have variables accessible in multiple modules.  Scope is very important because Corona is in effect a one-pass compiler, so if you declare something local after you try and use it, it will be nil or whatever global value the variable has.

A good read on Globals is:  http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Rob

Thank you Rob. When does screen refresh (or part of screen?) happen? When line properties change? And another question: if I need to calculate something long like weather model, for example 10 minutes of calculations. Is this possible? Or Corona is strictly screen-tied machine? I can’t understand the screen refresh and how/when it happens. I have read tutorials and guides by usual order and stands somewhere in the 1/3 of the whole documentation. I write code and it works. But I can’t understand above points.

This is one of those things you simply don’t need to worry about.   Corona updates the screen either 30 or 60 times per second.  If you need a long calculation, when its done, you make whatever drawing calls you need and Corona will take care of the rest.

Thank you Rob.