Rule groups which can use other local variables

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

Groups of rules, similar to custom rules but they cna use variables from the scope above

8 Likes

100% Yes.

I’m finding local variables very frustrating to use since they don’t cascade into custom abilities (I know you said “rules” but the same issue extends to abilities as well). I’m presently so frustrated that I’m about ready to quit using local variables.

Maybe T1 or someone will correct me if I’m wrong, but I believe in the future, once parameters are added, you’d be able to use those parameters so local variables could be inputs to the custom ability.

But in the mean time, while waiting for parameters, the neutering of custom abilities to prevent local variables from cascading into them is, in my opinion, ruining the ability to reuse code within your project.

@t1_hopscotch

8 Likes

Yeah parameters will be included, and are being worked on at the moment. They will be essentially local variables that exist inside that custom block (both custom abilities and custom rules), and you will be able to set inputs to them, including local variables from outer scopes.

In relation to the prevention of local variable scopes cascading into custom blocks — I do agree that without parameters, it limits use of local variables quite a lot in the meantime, where one is looking to reuse code.

Because if one is using local variables without being able to run different values for different places in code, it restricts you to using the same value. It leads to just having to code things manually again each time without using custom blocks, rather than being able to reuse code.

I think the neutering design is deliberate for when the ability to share custom blocks with other people is added, and it is at an in-between stage where we don’t have parameters yet to fill the other gap.

I can understand if you don’t have much use for local variables in the meantime (I initially felt the same) — their main advantage at the moment is being similar to Object Variables that don’t exist for all objects, and for things like counters for Repeat blocks, where you don’t need to reuse the code in another rule. But at least on the horizon, now that local variables have been implemented, custom blocks with parameters will be coming.

5 Likes

you can now use a local variable from scope above inside a custom ability by putting it in a parameter - although you wouldn’t be able to edit that local variable from the custom ability

1 Like

It copies the variable at the start, they are different variables.

It actually seems to copy it before it even runs any rules too.

2 Likes

I did notice this during testing but wasn’t sure what the behaviour ought to be for custom rules.

E.g. custom rule parameters also don’t read the live values of other variables like x position, y position

In this case, it uses the position of the objects at the start of the project.

  • When a variable is used as an argument in a custom rule, it uses the initialised value of the variable.
    • This makes it a bit difficult to use custom rules + parameters for reusing When code, for things like custom box collisions and radial collisions.
    • But i’m not sure what the behaviour should be — if it would make sense to have the default behaviour be to constantly check against the current value of a variable, which is what Whens do, compared to Ifs.
    • I guess this code could also be replaced if there was eventually the option to use functions that could return values, so i kind of hesitate to jump to the above option also.
2 Likes