Page 1 of 1

Intermittant screen update

Posted: Jul 8th, '17, 16:28
by SimpleSi
I expected this script should just toggle between the 2 messages but a lot of the time its displaying nothing
http://youtu.be/7jssFFFA5m0?hd=1

Re: Intermittant screen update

Posted: Jul 9th, '17, 01:21
by JohnM
If you use an "animate" loop or add a "wait" block to the "while" loop, this will work as expected.

Note that the "animate" block is the equivalent to the "forever" block in Scratch -- it pauses at the end of every iteration until the screen updates. Thus, it is limited to the speed of the display, typically 60 itererations/second. The while loop is like Scratch's "turbo" mode -- it runs tens of thousands of times times per second without waiting for the display. This makes "while" (and all the other loop blocks except "animate") great for bigger computational problems such as finding the number of unique words in "War and Peace".

In fact, the "animate" block is thus named to highlight it's importance for animation and other computations that should be tied to the display cycle.

Re: Intermittant screen update

Posted: Jul 9th, '17, 10:29
by SimpleSi
AAh - I see

I'll be adding that into my primer ASAP :)

Re: Intermittant screen update

Posted: Jul 9th, '17, 14:37
by SimpleSi
Okay - been playing/thinking

we could do with an animate while block

OR - and I hate to mention even mention this - a break loop block!

.... runs away.......

Re: Intermittant screen update

Posted: Jul 9th, '17, 20:01
by JohnM
You can turn any loop into a loop that works like animate by adding a "wait" block with no argument. A no-argument wait block just waits until the next display cycle.

A "break" block the exits the enclosing loop could be useful. Definitely worth considering adding later. (It has the downside that it could be confusing. For example, what does it do when its not inside a loop? (Possible answer: nothing; it's just ignored.) But "exit the loop early" is definitely a useful programming pattern/idiom.

Re: Intermittant screen update

Posted: Jul 10th, '17, 07:11
by SimpleSi
You can turn any loop into a loop that works like animate by adding a "wait" block with no argument. A no-argument wait block just waits until the next display cycle.
Aah :)

In that case, I'm thinking maybe remove animate block and just use the wait

Actually I'd get rid of "animate" and add "wait for screen refresh" (or something shorter!) and turn wait block into just a time wait block with the time being shown.

This would reduce having to "know" that the wait block has a dual purpose and teaching the concept of screen refreshing.

Re: Intermittant screen update

Posted: Jul 10th, '17, 09:32
by JohnM
Yes, it might be a more clear to have separate block for "wait for screen refresh".

I think it's useful to keep the "animate" block, since that is such a common case.

Thanks for thinking about this!

Re: Intermittant screen update

Posted: Jul 10th, '17, 14:09
by SimpleSi
Well I'm thinking animate could end up being the new forever if :)

A useful block but really shouldn't be there :)