Drawing Pad with Undo


I'm a little disappointed that no one asked why some of the events have Wait 0 blocks.

I was hoping Hops would really want to understand how Undo Pad v2 works, as there are some very valuable lessons.

Anyone care to render an explanation for why there are Wait 0 blocks? You have to give a detailed explanation for full credit :wink:

I'll post a full explanation tomorrow...


The wait blocks are there to wait a frame. I use wait 0 blocks often to get timing right. I don't use them well, though.


Good! Partial credit. :wink: Why do we need to delay a frame or 2? Being able to answer with specifics will allow you to "use them well" :smile:

BTW, there's also a Wait 0 here:


I recently learnt about using those. It's to wait for the next frame before running the next block.

I have been using it so that whatever blocks are run after the Wait 0 milliseconds are run after some other blocks in another rule are fired so that it runs in the correct order. I don't know how they are used in your Undo Pad, as I have not yet checked out the code.


Reasons I need to do that are to order layers the way I want them.

You might also want to do it to allow clones to set a few more variables before they get increased.
It is also useful for drawing things.
You can use it (possibly) to make backgrounds with complex trails work perfectly on every device.


That's probably to allow some other object to do something before it clears the screen.


Right... But still partial credit :innocent:


Uh huh... specifics... warning, you have to open the project and really think about the code... and understand some nuances of Hopscotch code execution flow (which I'll explain tomorrow)


Not possibly. Absolutely!


So I’m hoping a picture’s really worth a thousand words. To explain how Undo Pad v2 works, I thought I’d make a flow chart and a timing diagram. Then I thought, why not try to combine them.

Each row represents the order code is executed during a frame & each row is a separate frame. So time flows left to right, then up to down starting from the reddish events.

The exact sequence is determined by the order of the objects and the order of events in the objects in the project. Deriving the sequence from the project is unfortunately probably an entire topic of its own, but here are some key points

  • Some events only execute at 30 fps (so the flow arrows advance down to the next frame)
  • Some events execute at the expected 60 fps (so the flow arrows advance to the right within the same frame)
  • The conditionals (blue diamonds) and the first subsequent code block inside the conditional both execute in succession during the same frame
  • Wait 0 blocks don’t wait a specific amount of time, rather they are a fps independent wait of 1 frame

Key characteristics of the timing

  • One pen clone sets it’s X1/Y1 during the same frame as the next pen clone sets it’s X2/Y2. This means the Set X1 & Set Y1 must both be the 1st block in a When Object is Cloned event, while Set X2 & Set Y2 must both be the 3rd block.
  • During an Undo, the background redraw and both set positions of the pen redraws occur during the same frame

(Tap picture to enlarge)

Any questions? I hope the diagram is clear :smile:

Tagging those who liked the topic



Ah, so the process is as I thought, but I didn't think about setting the HSB of the clone trails. Maybe you could make a v3 with custom colors with this embedded - I'm pretty sure you could simply make three separate HSB variables for the color picked by the color chooser, then set those values to the clone/self HSB variables. I hope I didn't explain this in too much of a confusing matter ^^; but it's an idea I'd try out!

And also, I love how you preserve frames as much as possible - that's definitely a factor I should've thought about back when I Hopscotched.


Wow, that's pretty complicated! I love how clean and clear that the chart is. It really helped me understand it better, rather than just looking at a bunch of jumbled up code.

Wow, @BB-Box, that was within 5 seconds.


Oh, I was in this topic and then you posted, then I feel like I'm forced to like your post XD.


That's exactly how v2 works :smile: except without the custom color picker :wink:. Meaning there's global variables for the currently chosen color's H,S,B and each pen clone has self variables for that line segment's H,S,B (which are set to the global values when created). Adding customizable colors should then be relatively trivial.

I don't think that I'd make a v3 for customizable colors. I intentionally made the GUI simplistic. I thought that might encourage Hops to investigate the code and make their own version with the features they personally like :smirk: