Progress Scrollbar

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
roddy
Posts: 40
Joined: Tue Mar 04, 2014 7:24 pm

Progress Scrollbar

Post by roddy » Wed Apr 09, 2014 12:24 am

Hello - I'm trying to make a progress scrollbar go for 4 seconds and then show a Start button. The thumbPos goes to 40 then stops and in 4 seconds the Start button shows but with no visual effect. This worked at home on my PC but not at work on my Mac : /

I'm on LC 6.6.0

on preopencard
hide button "start"
set the thumbposition of scrollbar "splashScrollbar" to 20
end preopencard

on opencard
wait 1 second
set the thumbposition of scrollbar "splashScrollbar" to 40
wait 1 second
set the thumbposition of scrollbar "splashScrollbar" to 60
wait 1 second
set the thumbposition of scrollbar "splashScrollbar" to 80
wait 1 second
set the thumbposition of scrollbar "splashScrollbar" to 100
lock screen for visual effect
hide scrollbar "splashScrollbar"
hide field "load"
show button "start"
unlock screen with visual effect dissolve
end opencard

on closecard
show scrollbar "splashScrollbar"
show field "load"
end closecard

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Progress Scrollbar

Post by FourthWorld » Wed Apr 09, 2014 12:43 am

On OS X LC often draws faster than the rendering interrupt with show. You can correct for this by adding this line wherever you need a visual update that isn't happening:

wait 0 with messages
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Progress Scrollbar

Post by Simon » Wed Apr 09, 2014 1:16 am

Hi roddy,
In an effort to wean beginners away from "wait" (it's bad because it blocks up the engine) I 'd like to show you "send".

Code: Select all

on preopencard
   hide button "start"
   set the thumbposition of scrollbar "splashScrollbar" to 0
   goScroll
end preopencard

local x
on goScroll
   add 1 to x
   if x >= 400 then 
      lock screen for visual effect
      hide scrollbar "splashScrollbar"
      hide field "load"
      show button "start"
      unlock screen with visual effect dissolve
      exit goScroll
   end if
   set the thumbposition of scrollbar "splashScrollbar" to x/4
   send goScroll to me in 10 millisec --here is the magic
end goScroll
Nice and smooth huh?
But it's not how smooth it is that's important, in those 10 milliseconds the engine is free to get on with other tasks. In those 10 milliseconds it can sort a list of 10,000 names alphabetically.
Of course you are not doing that but it can update the scrollbar. :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

roddy
Posts: 40
Joined: Tue Mar 04, 2014 7:24 pm

Re: Progress Scrollbar

Post by roddy » Wed Apr 09, 2014 3:15 pm

Thank you Simon, very cool.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Progress Scrollbar

Post by FourthWorld » Wed Apr 09, 2014 6:49 pm

Simon wrote:In an effort to wean beginners away from "wait" (it's bad because it blocks up the engine) I 'd like to show you "send".
I don't think "wait" is necessarily bad, any more than global variables are "bad" even though some folks characterize them as such despite most languages supporting them. Each language feature has a place, so it's good to be familiar with the tradeoffs with them so you can choose the best fit for the task at hand.

"Wait" by itself does indeed block the flow of execution in the engine, but "0" reduce the duration to the amount of time it takes for the OS to process its event loop once, and "with messages" allows LC to handle messages triggered by other user interactions in the meantime.

With both "wait" and "send", idle plays a role, but in different, almost opposite, ways: "wait" often results in faster execution because the loop doesn't surrender control to idle until "wait" is explicitly called, while events handled by "send" are only processed at idle time.

Sometimes blocking execution is useful, but other times simulating threads can be useful. With LC's rich variety of syntax, we can have either as the task at hand requires.

Some time ago I put together a simple demonstration of simulated threading techniques for my local user group, and since it contains both "wait" and "send" forms it may be useful in exploring options here:
http://fourthworld.net/channels/lc/IdleHour.rev
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply