Html 5 test to refresh screen counter

Bringing your stacks to the web

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
AndreaT
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2
Joined: Mon Aug 26, 2013 6:49 pm
Location: Italy

Html 5 test to refresh screen counter

Post by AndreaT » Tue Nov 10, 2015 6:23 pm

Hi,

I have done a simple test with repeat structure, but in html5 build in the script not able to execute the refresh screen.
The script of the file attached, increments the counter of the label button only if it is executed in desktop mode:

Code: Select all

on mouseUp
   repeat with i = 1 to 2000
      set label of btn "contatore" to i 
      end repeat
   set label of btn "contatore" to 0
end mouseUp

Is it a funcionality that has to be implemented or is there another script solution to realize identical refresh screen counter for html 5 build in ?

thanks for clarification.
Andrea
Attachments
TestHTML5_counter.zip
test counter for html 5 export
(1.12 KiB) Downloaded 240 times

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Html 5 test to refresh screen counter

Post by Klaus » Tue Nov 10, 2015 7:04 pm

Buonasera Andrea,

1. welcome to the forum! :D

2. I am surprised this works on the desktop!?
Ususally the engine needs a little time to refresh the screen, so add a little "wait" and see if that works:

Code: Select all

...
repeat with i = 1 to 2000
      set label of btn "contatore" to i 
      wait 0 with messages
end repeat
...
Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Html 5 test to refresh screen counter

Post by bn » Tue Nov 10, 2015 9:22 pm

Hi Andrea,

currently HTML5 does not yet support "wait" and does not a screen refresh in a repeat loop, even if you would explicitely lock screen/unlock screen.

Until this happens you can do what you wanted to do this way:

Code: Select all

local sCounter -- important to place it here so every handler in this script can access it

on mouseUp
   put 0 into sCounter
   send countUp to me in 10 milliseconds
end mouseUp

on CountUp
   if sCounter >= 200 then
      set the label of button "contatore" to 0
      exit CountUp
   end if
   add 1 to sCounter
   set the label of button "contatore" to sCounter
   
   -- vary time here when next count increment should happen
   send CountUp to me in 10 milliseconds 
end CountUp
This uses "send in xx milliseconds" to handler CountUp and then the handler CountUp calls himself up to 200 in sCount.
sCount is a "script local variable" this means it is declared outside of any handler, usually at the top of the script. (see code). This has the advantage that any handler in this script (in this case of the button) and reade and write into this variable.

This works for HTML5 and for all other platforms. At times in HTML5 you have to play with the milliseconds if the script does not work as you expect. I tried this script with 3 milliseconds and it worked too. Other script might need 10 milliseconds.

If you have further questions feel free to ask.

Kind regards
Bernd

AndreaT
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2
Joined: Mon Aug 26, 2013 6:49 pm
Location: Italy

Re: Html 5 test to refresh screen counter

Post by AndreaT » Fri Nov 13, 2015 12:47 am

Thank you Klaus and Bernd for Helping.

The script of Bernd works fine in HTML5 and for me is an elegant solution. I have done only a test as educational purposes for myself and to look if that works.

In my opinion if the script strict style (repeat with i = 1 to 200...) works in html 5 as well as build in desktop would be faster. Is it wrong my meaning ?

Kind regards
Andrea

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Html 5 test to refresh screen counter

Post by bn » Fri Nov 13, 2015 1:26 am

Hi Andrea,
if the script strict style (repeat with i = 1 to 200...) works in html 5 as well as build in desktop would be faster
if you mean that the "strict" version is faster then the send in time, yes, generally speaking. But what takes time here is not the performance of repeat with versus send in time but the screen update.

I added a timing mechanism to the script and on average it screen update is about 16 milliseconds. That is a lot longer than the computation that takes a lot less than 1 milliseconds for each iteration.

So in animating things/showing something in fields etc it does not really matter which scripting style you use. If you do some processing without changing the display it does matter, but then there is no reason to use send in time anyways.
I was surprised that in HTML5 the script took about 2700 milliseconds to finish, whereas it was 3300 on the desktop.

Kind regards
Bernd

Post Reply

Return to “HTML5”