Probably, but i don’t really know
I don’t know
Actually, a sketch may be useful. It’ll give me something to reference for the time being, which may help me fully understand this feature and its function(s) even more.
I am confused can someone help explain what it is pls
Why you replying to me-
I don’t have a clue
You were the last reply at the time
Wow, great questions. Will do my best to answer - we’re still planning it all out, but hope this helps.
You’d be able to define scope at whatever level you wanted - and then the variable would be scoped to all code nested inside that level. You could change scope by moving the variable function around in your code.
We’re trying to keep it as simple as we can for MVP…initially, you may just see whatever local variables are available for the current scope display in the variables menu, but later maybe the scope highlights as you move the variable function around in the code.
The scope of a local variable will depend on where you place the variable function in the code…so you could definitely make it apply to all clones. Then I think you could use Clone Index to make them clone-specific.
We’ll probably disallow you from creating 2 variables in the same scope with the same name, then if you change the scope of one to where another one exists with the same name, we’ll preserve the one with the bigger scope…but still thinking through, so this may change.
Yes, by moving the variable function around.
You’d only be able to see the local variables if you’re in the scope it applies to…so you’d need to make a text object within that scope if you want it to display the value.
So for example, if you have a “when iPad is pressed” rule, and you made a local variable within that rule, you wouldn’t be able to use that same variable within other rules.
It also works with loops: if you made a local variable inside of an “if” loop, you would only be able to use it inside of that loop, and not anywhere else outside of it!
Ok thanks RawrBear
Thanks that makes more sense
It would honestly just help me keep my code more organized and efficient. Otherwise, it wouldn’t change to much for me personally
I personally think that if I could only choose one way to use local variables, they would be more convenient if they acted like per-clone object variables. It’d make cloning a lot more convenient if every variable was isolated/not linked between clones. I’ve never really used clone index that much, anyways, and although it may have its perks, having local variables act as object variables would make things a lot easier, cleaner and more intuitive to code.
Per se you use clones to generate obstacles over time. Instead of using one globally-seen object variable for loops within clones, like
j, you could use a local variable to make code more readable and independent, while your local variables reset per clone.
This readability and organization is actually way more useful than you might think, from developers that use dozens of variables in large scale seed dev projects! That alone would probably really help with refactoring those sorts of sections of code with a lot of them.
This is the paradigm I use for variables in Java as well as in Hopscotch currently, because generally local variables are redeclared per object and per loop. It sounds more confusing to me if variables were always linked. And this would also make more sense to me intuitively when making programming libraries, too, if object-oriented functions are planned for Hopscotch!
Having a choice between choosing local or global for every variable type (ie. object, game or user variables) would be very useful! So then if you wanted the local variable to link and act as a game variable, you could do that, or stick to a more realistic object-oriented approach with object variables, like I do for coding clones.
If you set a variable outside of a repeat block then use it inside the repeat block, would the repeat block use its own scope or the original one? Would the answer change for custom blocks? How would you make a custom block that for example takes a clone index and gives you a position to go to? How would you set the input (clone index) and use the output (x and y positions?)
For counting in repeat blocks, and for custom blocks that need input/give output.
If I had a custom block which takes a number and gives a position, it takes multiple frames to have a usable output, and without local variables the output is an object variable. This means that I cannot use it multiple times at once in the same object, since they might mess with each other or ruin the other’s output. With local variables, hopefully I could have the output only in the scope of the ability that the custom block is inside of.
That would be very useful too.
I do this also but I end up with 3 or 4 sets of each because either finding the old set is difficult with all the variables or I’m already using it somewehre else in the object. Local variables would fix that problem.
Another question: How big can the scope get? Would there eventually be a way to have variables scoped to custom rules? Maybe give input to custom rules? So for example, a rule that does something when it receives some message, but needs to be reused and has multiple rules inside of it. You could give it the message name as input.
Object variables are per-clone. Am I misunderstanding your post?
Not at all! I just wanted to be clear.
Questions for you
- Does the concept of local variables make sense to you?
- What questions do you have about how it would work?
I don’t see it
- How would you use local variables in Hopscotch today?
- What do you think local variables would allow you to make in Hopscotch that you haven’t been able to make before? Maybe…idk…
This for the people who have the subscription?
This feature doesn’t exist yet as far as I know. THT is just thinking about it, and getting feedback here about its design.
Here you go!