Discuss Scratch
- Maximouse
-
Scratcher
1000+ posts
Local Variables
And “New variable” dialog:

The “cloud variable” checkbox would be hidden if you select “local variable”. If you choose “local variable” and click “OK”, a “create variable” block would appear in your workspace.

The “cloud variable” checkbox would be hidden if you select “local variable”. If you choose “local variable” and click “OK”, a “create variable” block would appear in your workspace.
- DrGaming_92Games
-
Scratcher
100+ posts
Local Variables
What about local lists?create variables (local variable :: #ffb366) (local list :: list) {
set [local variable v] to (10)
add (local variable) to [local list v]
} :: variables
That's an interesting idea, you should make your own topic so this can get discussed more directly.
- Maximouse
-
Scratcher
1000+ posts
Local Variables
What about local lists?create variables (local variable :: #ffb366) (local list :: list) {
set [local variable v] to (10)
add (local variable) to [local list v]
} :: variables
That's an interesting idea, you should make your own topic so this can get discussed more directly.
I'm not sure if this could be a separate topic because it requires the block suggested here. I think that suggestions should be independent of each other.
- DrGaming_92Games
-
Scratcher
100+ posts
Local Variables
What about local lists?create variables (local variable :: #ffb366) (local list :: list) {
set [local variable v] to (10)
add (local variable) to [local list v]
} :: variables
That's an interesting idea, you should make your own topic so this can get discussed more directly.
I'm not sure if this could be a separate topic because it requires the block suggested here. I think that suggestions should be independent of each other.
Perhaps it could be its own c-block
- DrGaming_92Games
-
Scratcher
100+ posts
Local Variables
bump, and @Maximouse, thank you for the images, those were really helpful and I forgot to thank you earlier. After having thought about the look of the local variables, I think that a different color may not fit with Scratch. And also, what if another global or sprite only variable is defined, what happens to the local variables. Does the local definition take precedents? Should you just not be able to make a global variable with the same name as a local variable? Feedback is appreciated.
- Maximouse
-
Scratcher
1000+ posts
Local Variables
bump, and @Maximouse, thank you for the images, those were really helpful and I forgot to thank you earlier. After having thought about the look of the local variables, I think that a different color may not fit with Scratch. And also, what if another global or sprite only variable is defined, what happens to the local variables. Does the local definition take precedents? Should you just not be able to make a global variable with the same name as a local variable? Feedback is appreciated.
I think that it shouldn't be possible to make a local variable with the same name as a global variable, just like global and this sprite only variables.
- LandonHarter
-
Scratcher
1000+ posts
Local Variables
repeat (83)
create variable (var) (+:: grey) {
. . .
} :: variables
end
- HTML-Fan
-
Scratcher
1000+ posts
Local Variables
I thinkt that it's a good idea. A problem: Currently you can drop function parameters outside of the function:
when green flag clickedHow can I make input purple? :: custom works, but not really. Or does it and it changes the color when you create a clone?
say (input :: custom)
define func (input)
Last edited by HTML-Fan (June 27, 2020 18:43:41)
- Maximouse
-
Scratcher
1000+ posts
Local Variables
I thinkt that it's a good idea. A problem: Currently you can drop function parameters outside of the function:According to the OP, trying to use a local variable where it isn't defined would just return zero.when green flag clicked
say (input :: custom)
define func (input)
- HTML-Fan
-
Scratcher
1000+ posts
Local Variables
Yes, but you should just not be able to drop the variable.
And you can make
And you can make
define func (parameter) (another parameter) (parameter)and that's confusing because two different parameters have the same name.
- scratchastroLOL
-
Scratcher
1000+ posts
Local Variables
but i don't really understand why it should be a C block.
and local lists
create local variable named [] :: variables
(local variable: [] :: variables)
delete (localvar v) :: variables
and local lists
create local lists (local list :: list) (+ :: grey) {
add [Hi man!] to [local list v]
say (item (1 v) of [local list v] :: list)
} :: listLast edited by scratchastroLOL (June 29, 2020 21:07:13)
- whiteandblackcat
-
Scratcher
1000+ posts
Local Variables
This is a really neat idea, and I think it would me easier to use and more straightforward than other local variable ideas I've seen.
Also - yes, it's like a list. But these are easier to use. Especially because when you delete one variable in a list, they all get shuffled up, so you could be referencing the wrong variable. And yes, there are methods to deal with that. But they just get harder and harder to read when you're coding. Who wants to put this
Also @Maximouse - nice mockups, but if you set it that you have to create the variables beforehand, then you may as well not have temporary variables. Isn't the whole point of most suggestions of this kind that you can name them? So perhaps it would be better for the C block to have an editable input, so you can make a new variable named whatever you need it to be.
I mean, this works too, and a C block could sometimes be misleading. But I think a C block helps you keep track of when you can use variables and when you can't; it's a bit cleaner and you can always tell whether the variable will exist or not.
Also, if you had
I thought of a problem: visually telling the difference between local variables and normal variables. I have 2 ideas for this, either make the local variables a lighter orange, or add a little icon next to it the same way cloud variables do (obviously with a different symbol).I agree; they'd need to be a bit different. I like a lighter orange, but that might be difficult in terms of getting local variable blocks confused with variable blocks and/or control blocks. Perhaps an icon would be better, although I have no idea what you would use.
Also - yes, it's like a list. But these are easier to use. Especially because when you delete one variable in a list, they all get shuffled up, so you could be referencing the wrong variable. And yes, there are methods to deal with that. But they just get harder and harder to read when you're coding. Who wants to put this
(item (item number of [variable name] in [varNames v]::list) of [varVals v])instead of this?
(variable name)
Also @Maximouse - nice mockups, but if you set it that you have to create the variables beforehand, then you may as well not have temporary variables. Isn't the whole point of most suggestions of this kind that you can name them? So perhaps it would be better for the C block to have an editable input, so you can make a new variable named whatever you need it to be.
but i don't really understand why it should be a C block.create local variable named [] :: variables
(local variable: [] :: variables)
delete (localvar v) :: variables
and local listscreate local lists (local list :: list) (+ :: grey) {
add [Hi man!] to [local list v]
say (item (1 v) of [local list v] :: list)
} :: list
I mean, this works too, and a C block could sometimes be misleading. But I think a C block helps you keep track of when you can use variables and when you can't; it's a bit cleaner and you can always tell whether the variable will exist or not.
Also, if you had
create variable (a) {
set [a v] to (11)
}::variables
...
create variable (a) {
change [a v] by (1)
say (a)
}::variableswhat would this return; 11 or 1? There may be no reason to code like this, but scratch needs to know how to respond.- Maximouse
-
Scratcher
1000+ posts
Local Variables
As I said before, Snap! uses a location icon:I thought of a problem: visually telling the difference between local variables and normal variables. I have 2 ideas for this, either make the local variables a lighter orange, or add a little icon next to it the same way cloud variables do (obviously with a different symbol).I agree; they'd need to be a bit different. I like a lighter orange, but that might be difficult in terms of getting local variable blocks confused with variable blocks and/or control blocks. Perhaps an icon would be better, although I have no idea what you would use.

Also @Maximouse - nice mockups, but if you set it that you have to create the variables beforehand, then you may as well not have temporary variables. Isn't the whole point of most suggestions of this kind that you can name them? So perhaps it would be better for the C block to have an editable input, so you can make a new variable named whatever you need it to be.I don't understand exactly what you want to say – the point was that this block would not appear in the palette because that could be confusing – instead it would be an option in the Create variable dialog.
Also, if you hadIt would return 1. And thiscreate variable (a) {what would this return; 11 or 1? There may be no reason to code like this, but scratch needs to know how to respond.
set [a v] to (11)
}::variables
...
create variable (a) {
change [a v] by (1)
say (a)
}::variables
create variable (a) {
set [a v] to (11)
create variable (a) {
change [a v] by (1)
say (a)
} :: variables
say (a)
} :: variableswould say 1, then 11.- whiteandblackcat
-
Scratcher
1000+ posts
Local Variables
what's the point of it then? You may as well just make a normal variable, which is less confusing.Also @Maximouse - nice mockups, but if you set it that you have to create the variables beforehand, then you may as well not have temporary variables. Isn't the whole point of most suggestions of this kind that you can name them? So perhaps it would be better for the C block to have an editable input, so you can make a new variable named whatever you need it to be.I don't understand exactly what you want to say – the point was that this block would not appear in the palette because that could be confusing – instead it would be an option in the Create variable dialog.
Last edited by whiteandblackcat (July 1, 2020 06:59:38)
- Maximouse
-
Scratcher
1000+ posts
Local Variables
what's the point of it then? You may as well just make a normal variable, which is less confusing.You can create multiple local variables with the same name, used in different places. They don't appear in the palette. And so on.
- whiteandblackcat
-
Scratcher
1000+ posts
Local Variables
I don't see a point of that.what's the point of it then? You may as well just make a normal variable, which is less confusing.You can create multiple local variables with the same name, used in different places. They don't appear in the palette. And so on.
- Maximouse
-
Scratcher
1000+ posts
Local Variables
If you have lots of variables but each is only used in one place the list of variables becomes cluttered, right? Local variables would solve that. The C block wouldn't appear in the palette, instead it could be accessed by selecting “Local variable” when making a variableI don't see a point of that.what's the point of it then? You may as well just make a normal variable, which is less confusing.You can create multiple local variables with the same name, used in different places. They don't appear in the palette. And so on.

After clicking OK, a block like this would appear:
create variable (local variable) {
} :: variables





