Intermittant screen update

Report bugs. Post bug workarounds or fixes

Moderator: MSandro

Post Reply
SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Intermittant screen update

Post by SimpleSi » Jul 8th, '17, 16:28

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

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Intermittant screen update

Post by JohnM » Jul 9th, '17, 01:21

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.

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: Intermittant screen update

Post by SimpleSi » Jul 9th, '17, 10:29

AAh - I see

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

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: Intermittant screen update

Post by SimpleSi » Jul 9th, '17, 14:37

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.......

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Intermittant screen update

Post by JohnM » Jul 9th, '17, 20:01

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.

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: Intermittant screen update

Post by SimpleSi » Jul 10th, '17, 07:11

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.

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Intermittant screen update

Post by JohnM » Jul 10th, '17, 09:32

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!

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: Intermittant screen update

Post by SimpleSi » Jul 10th, '17, 14:09

Well I'm thinking animate could end up being the new forever if :)

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

Post Reply