Containers (entrance & exit) that don’t delay until next frame

A feature I’d like to see in Hopscotch is:

…for the code execution upon entrance to and exit from Containers (If Then, If Then Else, Repeat, and custom Abilities) into keep playing intra-frame, rather than delaying until the next frame regardless of the next block to be played.

In this way complex logical sequences, including reused code, could be created that would execute with improved performance.

I believe similar results could be achieved as requested in this discussion on turbo mode, except it would be completely transparent to new users or those not needing fast logical sequences.

I’d use it for this type of project:

  • Any project with computationally complex sequences, especially those that can’t be achieved in a single nested sequence of If Then Else blocks.
  • Reuse of code in multiple code paths that today can’t be custom abilities due to the frame delay on entrance/exit.

Here are some examples of Hopscotch code that could be improved if we had this:

Opportunities for improvement are numerous.

1)_This entire sequence for all code paths could be 1 frame, instead of either 4 or 5 frames (depending on the path):

Set {variable} to {math}
If {logical statement} Then
    Set {variable} to {math}
End
If {logical statement} Then
    Set {variable} to {math}
    {Custom ability}
        Set {variable} to {math}
        Set {variable} to {math}
    End ability 
Else
    If {logical statement} Then
        Set {variable} to {math}
    Else
        {Custom ability}
            Set {variable} to {math}
            Set {variable} to {math}
        End ability 
    End
End
Set {variable} to {math}

*of particular importance is the custom ability, to allow code reuse & simplification in this type of scenario.

2)_Additionally, readability of HS code could be significantly improved in scenarios where nested If Then blocks make the usable space too narrow to effectively view the blocks inside. Without the delays entering/exiting If Thens, they wouldn’t have to be nested!

Caveats

Recursive abilities could create infinite loops and freeze the program, so perhaps to protect users from that eventuality custom Abilities, only upon recursion, would need to delay until the next frame.

@Yuanyuan @t1_hopscotch @AwesomeOnion

11 Likes

Here’s another specific example of what I’m advocating for improvement of.

A chess project I’m working on has, in part, the following code for the computer player:

This is just one of many opportunities for improvement in this chess project, but in this simple example, similar code is needed for each of the types of pieces. The code in the middle is unique to each piece type, the first four & last 2 lines are common code. Ordinarily those reused blocks could be put in a custom ability, but in this case I can’t do that due to the performance impact of the “container/frame delays” the custom abilities would cause. E.g, a 30 second calculation would then take 1 1/2 minutes. (as shown, I couldn’t use custom abilities anyways due to my unfortunate choice of local variables. But if the “container delays” didn’t exist, the local variables could be changed to object variables.)

I also can’t put the first 4 lines before the sequence of If Thens or the last 2 lines after the sequence of If Thens, as those containers also delay a frame entering & exiting. So again, I’d have 3x slower calculations.

10 Likes

This sounds like something that I think could be useful! If I understood the comparison with a Turbo mode right, this basically brings the same improvement that the turbo mode does in terms of speed, but instead of having it as a separate mode, it becomes an integrated improvement in Hopscotch instead?

6 Likes

Exactly. That was the thought.

6 Likes

Great suggestion, but I’m unsure if this is possible. On the browser side of things, maybe, as I know Scratch can execute its code instantly in most cases.

5 Likes

I definitely am in favor of this, as it would mean quicker execution.

I personally think delay should only occur on blocks where animation occurs, such as Move By, Move Forward, Turn, etc.

One con would be everyone would have to add a wait 0 block inside their repeat times container to get the same effect as before, which can sometimes be a major hassle.

5 Likes

Adding this to our github issues list.

8 Likes

Thank you.

Btw, I found a partial workaround for the bit quoted. I’m guessing this behavior wasn’t intended, but I’m using it and calling it a “feature” :slightly_smiling_face:

All of the Set blocks, including those in the Custom Ability, shown below occur “immediately” and during the same frame. Using a Custom Ability with a Check If 7=7 (edit: or Repeat Times 1) allows the execution to keep running infra-frame.

Remove the Check If or change it to include a variable and the Custom Ability delays the internal Sets until the next frame.

*Edit - Also works with a Repeat Times 1 inside the Custom Ability

5 Likes

It also works with a custom ability inside a different custom ability. Although it is more costly, if you know what I mean…

2 Likes

May I ask what the GitHub issues list is? If you don’t want to share that info, that’s fine. Also, how often do you update your Hopscotch Language Roadmap on Airtable?

1 Like