Version 3.48.0 Official Topic

Hey Hopscotchers,

Have you ever made a project that needed a whole bunch of variables, but each one was only needed for one or two functions?

Now, instead of cluttering up your variables menu with a ton of global variables, you can use local variables.

With local variables, you can create a variable and define a local ‘scope’ for it - meaning, it will be usable only for specific blocks of code that you define. Local variables will only show up in your variables menu when you’re editing functions within that scope.

Other Updates

This version also includes the ability to add images from your files to projects. This will allow you to more easily add photos with transparent backgrounds to your creations!

Bug fixes include an issue where the Z index of objects that have been sent to front or back is affected unexpectedly when another object uses Z index.

We love to hear from you! Send feedback to hello@gethopscotch.com.

31 Likes

Cool can’t wait
(First)
This will be very useful

3 Likes

Awesome! (E)

This is a huge step forwards, and I can’t wait to try this out

4 Likes

This is an awesome update. Keep up the great work!

3 Likes

Ayyy, yissssssss, local vars whoo hoo!

4 Likes

Best feature of update ever! I have had trouble adding some images with transparent backgrounds in the past (especially when they are only 128 by 128 in size)… besides Local Variables, of course.

6 Likes

hey, one question
when we put Set Variable To Whatever outside the magenta blocks, will it be run once or at every frame?

3 Likes

If outside of a magenta block, the set variable will run once (think of it as a define variable with value). However, I think it will run every time a scene is changed, though.

7 Likes

I am so happy now there are local variables
I’ve been waiting for it
Why am I looking for private variables

2 Likes

:warning:Caution :warning:

There are a few limitations of local variables to be aware of:

Local variables can not be renamed

Choose your local variable names carefully. If you later decide to change the name, you will have to create a new local variable and replace it manually everywhere it’s used (THT, hopefully this can/will be fixed in an future update?)

Local variables do not cascade into Custom Abilities

My understanding is that this was intentional so that in the future custom abilities can be shared.

The help text is misleading

(This only appears if you long press a local variable in the bottom menu. If you long press “New Variable” you get a different help text which is common to local, object, & global variables…)

This is just my opinion, but I believe “Great for keeping track of values like score and health!” is very misleading. Can you do that with local variables? Sure, if you create the correct scope for the variable and then use broadcasted messages and/or possibly additional global variables all the objects to communicate. To me, that makes it a bad example for users who are unfamiliar with the concept of private variables.

10 Likes

hmm, renaming is an interesting use case.

We probably won’t tackle it in the near future because the way that local variables work is that they are keyed just on the name. We basically check after the fact to see if the same variable is used in different places rather than them having some common ancestors. So it feels like a refactor tool sort of feature which is out of scope for now. (i.e. we want to work on more important things like adding parameters to functions)

12 Likes

Yes, please! :white_check_mark:

Thank you for all your hárd work. Local variables are a great addition to HS. I haven’t had the chance yet, but I’m looking forward to discussing local vars with my kids and seeing how easily it clicks. Are any new tutorial videos planned to explain local variables?

9 Likes

Not that I know of, but the “Bounce” Custom Rule does now use Local Variables instead of Object Variables like it did before.

3 Likes

Is there any chance local vars will be removed?

1 Like

What makes you say that?

1 Like

My game uses a lot (about 10 a scene, at least) of variables, and using local vars would declutter the variable tab

But I don’t want my game to break if local variables are removed, so I was just wondering

1 Like

There is no chance of Local Variables being removed, mainly because some of the upcoming features cannot live without them. Specifically speaking: Community Garden (as Yuanyuan has confirmed it’s called), which is basically the ability to share code snippets to the community.

Refer to the Quarterly Roadmap for more detail on the above.

3 Likes

Ah

Okay, thanks!

2 Likes

Yay one less thing I have to code a hacky workaround for! Great addition to the language!

3 Likes

@AwesomeOnion can I have a pm with you?

Thanks
Jye

1 Like