Newprogressview Shows Progress After Leaving The For Loop

– Testing newProgressView

– File name: main.lua


local widget = require ( “widget” )
widget.setTheme( “theme_ios” )
local widgetGroup = display.newGroup()

 

print (“start”)
local progressView = widget.newProgressView{
   left = 70,
   top = 190,
   isAnimated = true,
}
local currentProgress = 0.0
widgetGroup:insert( progressView )
amt = 1000
jump = 100 / amt
for x=1,amt do
   print(“step by step, but no progress is shown yet!”…x, jump, currentProgress)
   currentProgress = currentProgress + jump
   progressView:setProgress( currentProgress )
end
print(“And now after the loop it shows the progress… that isn’t very usefull !”)
print(“Am I doing something the wrong way here?”)

widget.newProgressView() is single use only for now, you cannot set progress to 1 and then set it to lower value, it will remember highest value

Your for loop is going to execute very quickly and likely all of the steps you are making are going to happen in a single display frame. 

Rob, but is a bug, if you set progress to this widget to 0.7 and then to 0.4 it will never be updated to 0.4 (to lower value)

you need to recreate widget to be able to set its progress to lower value.

 

Actually not what was reported in the first post, but important also.

I understand that Tom, but his numbers should be counting up if I read his code correctly.   currentProgress starts at 0 and he adds 0.1 to it 1000 times.   That bug aside, that loop is going to execute in less than 1/30th of a second and that’s only one screen update.

It does not matter whether the work in the loop takes more time to process. The progress bar starts running only after the loop has finished! I just brought the problem down to this code, to show that it is not working properly for me. In reality the loop takes about 15 to 20 seconds. After that the progress bar shows and runs pretty quickyly to its end.

becasue its animated, turn animation off and you will see

If I turn of animation, the progress bar shows right after the loop, but with a full bar. So in that case I only get a progress bar that has already ended when it first shows.

I have added some code to the loop, so that it will take more time to complete. Perhaps that clarifies my problem better. I am using this version of Corona SDK by the way:

 

Copyright © 2009-2012  C o r o n a   L a b s   I n c .
        Version: 2.0.0
        Build: 2012.971

 

----- Updated testcode


– Testing newProgressView

– File name: main.lua


local widget = require ( “widget” )
widget.setTheme( “theme_ios” )
local widgetGroup = display.newGroup()
– Database connectie
require “sqlite3”
– Open Clubbin.db.  If the file doesn’t exist it will be created
local path = system.pathForFile(“clubbin.db”, system.DocumentsDirectory)
  db = sqlite3.open( path )
–Handle the applicationExit event to close the db
local function onSystemEvent( event )
   if( event.type == “applicationExit” ) then             
      db:close()
   end
end
local droptesttable = [[DROP TABLE testtable;]]
local createtesttable = [[CREATE TABLE IF NOT EXISTS testtable
    (testfield1 integer,
     testfield2 integer,
     testfield3 text);]]
db:exec (droptesttable)
if db:errcode() > 0 then
   print (“statement:”…droptesttable)
   print (“error:”…dberrcode() )
end
db:exec (createtesttable)
if db:errcode() > 0 then
   print (“statement:”…createtesttable)
   print (“error:”…dberrcode() )
end

 

local progressView = widget.newProgressView{
   left = 70,
   top = 190,
   isAnimated = true,
}
local currentProgress = 0.0
widgetGroup:insert( progressView )
amt = 10
jump = 1 / amt
print (“started:”…os.time())

 

for x=1,amt do
   for y=1, 10 do
      local inserttesttable = [[INSERT INTO testtable VALUES (]]…x…[[,]]…y…[[, ‘]]…“text”…x…"_"…y…[[’);]]
      print (inserttesttable )
      db:exec (inserttesttable )
      if db:errcode() > 0 then
         print (“statement:”…inserttesttable )
         print (“error:”…db:errcode() )
      end
   end
   print(“step by step, but no progress is shown yet!”…x, jump, currentProgress)
   currentProgress = currentProgress + jump
   progressView:setProgress( currentProgress )
end
–print (os.time())  – I commented this, because it causes too much output. The simulator then looses the first lines written.
–for row in db:nrows(“SELECT * FROM testtable”) do
   --print (row.testfield1, row.testfield2, row.testfield3)
–end 
print (“ended:”…os.time())
print(“And now after the loop ends (after several seconds on my machine) it shows the progress…”)
print(“I must be doing something wrong, but I can’t find it!”)

Hi @HansVriezen,

Perhaps this was an honest oversight, but Widgets 2.0 is not part of Build #971. You must use the latest daily build to take advantage of all the latest Widgets.

 

Brent

widget.newProgressView() is single use only for now, you cannot set progress to 1 and then set it to lower value, it will remember highest value

Your for loop is going to execute very quickly and likely all of the steps you are making are going to happen in a single display frame. 

Rob, but is a bug, if you set progress to this widget to 0.7 and then to 0.4 it will never be updated to 0.4 (to lower value)

you need to recreate widget to be able to set its progress to lower value.

 

Actually not what was reported in the first post, but important also.

I understand that Tom, but his numbers should be counting up if I read his code correctly.   currentProgress starts at 0 and he adds 0.1 to it 1000 times.   That bug aside, that loop is going to execute in less than 1/30th of a second and that’s only one screen update.

It does not matter whether the work in the loop takes more time to process. The progress bar starts running only after the loop has finished! I just brought the problem down to this code, to show that it is not working properly for me. In reality the loop takes about 15 to 20 seconds. After that the progress bar shows and runs pretty quickyly to its end.

becasue its animated, turn animation off and you will see

If I turn of animation, the progress bar shows right after the loop, but with a full bar. So in that case I only get a progress bar that has already ended when it first shows.

I have added some code to the loop, so that it will take more time to complete. Perhaps that clarifies my problem better. I am using this version of Corona SDK by the way:

 

Copyright © 2009-2012  C o r o n a   L a b s   I n c .
        Version: 2.0.0
        Build: 2012.971

 

----- Updated testcode


– Testing newProgressView

– File name: main.lua


local widget = require ( “widget” )
widget.setTheme( “theme_ios” )
local widgetGroup = display.newGroup()
– Database connectie
require “sqlite3”
– Open Clubbin.db.  If the file doesn’t exist it will be created
local path = system.pathForFile(“clubbin.db”, system.DocumentsDirectory)
  db = sqlite3.open( path )
–Handle the applicationExit event to close the db
local function onSystemEvent( event )
   if( event.type == “applicationExit” ) then             
      db:close()
   end
end
local droptesttable = [[DROP TABLE testtable;]]
local createtesttable = [[CREATE TABLE IF NOT EXISTS testtable
    (testfield1 integer,
     testfield2 integer,
     testfield3 text);]]
db:exec (droptesttable)
if db:errcode() > 0 then
   print (“statement:”…droptesttable)
   print (“error:”…dberrcode() )
end
db:exec (createtesttable)
if db:errcode() > 0 then
   print (“statement:”…createtesttable)
   print (“error:”…dberrcode() )
end

 

local progressView = widget.newProgressView{
   left = 70,
   top = 190,
   isAnimated = true,
}
local currentProgress = 0.0
widgetGroup:insert( progressView )
amt = 10
jump = 1 / amt
print (“started:”…os.time())

 

for x=1,amt do
   for y=1, 10 do
      local inserttesttable = [[INSERT INTO testtable VALUES (]]…x…[[,]]…y…[[, ‘]]…“text”…x…"_"…y…[[’);]]
      print (inserttesttable )
      db:exec (inserttesttable )
      if db:errcode() > 0 then
         print (“statement:”…inserttesttable )
         print (“error:”…db:errcode() )
      end
   end
   print(“step by step, but no progress is shown yet!”…x, jump, currentProgress)
   currentProgress = currentProgress + jump
   progressView:setProgress( currentProgress )
end
–print (os.time())  – I commented this, because it causes too much output. The simulator then looses the first lines written.
–for row in db:nrows(“SELECT * FROM testtable”) do
   --print (row.testfield1, row.testfield2, row.testfield3)
–end 
print (“ended:”…os.time())
print(“And now after the loop ends (after several seconds on my machine) it shows the progress…”)
print(“I must be doing something wrong, but I can’t find it!”)

Hi @HansVriezen,

Perhaps this was an honest oversight, but Widgets 2.0 is not part of Build #971. You must use the latest daily build to take advantage of all the latest Widgets.

 

Brent

I have upgraded to 2013.1076

Still have the same problem as far as I can see. Below the code I just used to test it, followed by the output in the simulator.

During the For loop, no updates are shown on the screen but after the For loop ends, the progressbar comes to life.

Am I doing something wrong here, or is the progressbar not supposed to be able to show progress from inside a For loop?


local widget = require( “widget” )

– Database connectie

require “sqlite3”

– Open test.db.  If the file doesn’t exist it will be created

local path = system.pathForFile(“test.db”, system.DocumentsDirectory)

db = sqlite3.open( path )

–Handle the applicationExit event to close the db

local function onSystemEvent( event )

   if( event.type == “applicationExit” ) then              

      db:close()

   end

end

local droptesttable = [[DROP TABLE testtable;]]

local createtesttable = [[CREATE TABLE IF NOT EXISTS testtable

    (testfield1 integer,

     testfield2 integer,

     testfield3 text);]]

db:exec (droptesttable)

if db:errcode() > 0 then

   print (“statement:”…droptesttable)

   print (“error:”…db:errcode() )

end

db:exec (createtesttable)

if db:errcode() > 0 then

   print (“statement:”…createtesttable)

   print (“error:”…db:errcode() )

end

– Create a new progressView

local newProgressView = widget.newProgressView

{

    left = 50,

    top = 200,

    width = 200,

    isAnimated = true,

}

local currentProgress = 0

amt = 5

jump = 1 / amt

print (“started:”…os.time())

for x=1,amt do

   for y=1, 10 do

      local inserttesttable = [[INSERT INTO testtable VALUES (]]…x…[[,]]…y…[[, ‘]]…“text”…x…"_"…y…[[’);]]

      print (inserttesttable )

      db:exec (inserttesttable )

      if db:errcode() > 0 then

         print (“statement:”…inserttesttable )

         print (“error:”…db:errcode() )

      end

   end

   currentProgress = currentProgress + jump

   print(“step by step, but no progress is shown yet!”…x, jump, currentProgress)

   newProgressView:setProgress( currentProgress )

end

print (“ended:”…os.time())

------------------------------------------------------------------------------------------------------------------------------------------------------------ Output below

------------------------------------------------------------------------------------------------------------------------------------------------------------Copyright © 2009-2013  C o r o n a   L a b s   I n c .

        Version: 2.0.0

        Build: 2013.1076

started:1367953134

INSERT INTO testtable VALUES (1, 1, ‘text1_1’);

INSERT INTO testtable VALUES (1, 2, ‘text1_2’);

INSERT INTO testtable VALUES (1, 3, ‘text1_3’);

INSERT INTO testtable VALUES (1, 4, ‘text1_4’);

INSERT INTO testtable VALUES (1, 5, ‘text1_5’);

INSERT INTO testtable VALUES (1, 6, ‘text1_6’);

INSERT INTO testtable VALUES (1, 7, ‘text1_7’);

INSERT INTO testtable VALUES (1, 8, ‘text1_8’);

INSERT INTO testtable VALUES (1, 9, ‘text1_9’);

INSERT INTO testtable VALUES (1, 10, ‘text1_10’);

step by step, but no progress is shown yet!1    0.2     0.2

INSERT INTO testtable VALUES (2, 1, ‘text2_1’);

INSERT INTO testtable VALUES (2, 2, ‘text2_2’);

INSERT INTO testtable VALUES (2, 3, ‘text2_3’);

INSERT INTO testtable VALUES (2, 4, ‘text2_4’);

INSERT INTO testtable VALUES (2, 5, ‘text2_5’);

INSERT INTO testtable VALUES (2, 6, ‘text2_6’);

INSERT INTO testtable VALUES (2, 7, ‘text2_7’);

INSERT INTO testtable VALUES (2, 8, ‘text2_8’);

INSERT INTO testtable VALUES (2, 9, ‘text2_9’);

INSERT INTO testtable VALUES (2, 10, ‘text2_10’);

step by step, but no progress is shown yet!2    0.2     0.4

INSERT INTO testtable VALUES (3, 1, ‘text3_1’);

INSERT INTO testtable VALUES (3, 2, ‘text3_2’);

INSERT INTO testtable VALUES (3, 3, ‘text3_3’);

INSERT INTO testtable VALUES (3, 4, ‘text3_4’);

INSERT INTO testtable VALUES (3, 5, ‘text3_5’);

INSERT INTO testtable VALUES (3, 6, ‘text3_6’);

INSERT INTO testtable VALUES (3, 7, ‘text3_7’);

INSERT INTO testtable VALUES (3, 8, ‘text3_8’);

INSERT INTO testtable VALUES (3, 9, ‘text3_9’);

INSERT INTO testtable VALUES (3, 10, ‘text3_10’);

step by step, but no progress is shown yet!3    0.2     0.6

INSERT INTO testtable VALUES (4, 1, ‘text4_1’);

INSERT INTO testtable VALUES (4, 2, ‘text4_2’);

INSERT INTO testtable VALUES (4, 3, ‘text4_3’);

INSERT INTO testtable VALUES (4, 4, ‘text4_4’);

INSERT INTO testtable VALUES (4, 5, ‘text4_5’);

INSERT INTO testtable VALUES (4, 6, ‘text4_6’);

INSERT INTO testtable VALUES (4, 7, ‘text4_7’);

INSERT INTO testtable VALUES (4, 8, ‘text4_8’);

INSERT INTO testtable VALUES (4, 9, ‘text4_9’);

INSERT INTO testtable VALUES (4, 10, ‘text4_10’);

step by step, but no progress is shown yet!4    0.2     0.8

INSERT INTO testtable VALUES (5, 1, ‘text5_1’);

INSERT INTO testtable VALUES (5, 2, ‘text5_2’);

INSERT INTO testtable VALUES (5, 3, ‘text5_3’);

INSERT INTO testtable VALUES (5, 4, ‘text5_4’);

INSERT INTO testtable VALUES (5, 5, ‘text5_5’);

INSERT INTO testtable VALUES (5, 6, ‘text5_6’);

INSERT INTO testtable VALUES (5, 7, ‘text5_7’);

INSERT INTO testtable VALUES (5, 8, ‘text5_8’);

INSERT INTO testtable VALUES (5, 9, ‘text5_9’);

INSERT INTO testtable VALUES (5, 10, ‘text5_10’);

step by step, but no progress is shown yet!5    0.2     1

ended:1367953138