Discuss Scratch
- 0037318
-
100+ posts
Make, read, and delete variable blocks.
This is a simple suggestion. Basically, you would have 4 new blocks that look like this:
There are at least 2 reasons why these 3 blocks in particular should be added.
To help you understand this, here is a script that allows the user to add a certain amount to a certain variable:
As you can see, this script requires 2 variables (cluttering the variable space) and quite a lot of code. With these blocks, you could do the same thing like this:
Do you see how much simpler and more efficient the last one is compared to the first one? That is why these blocks should be added.
make variable called [name] value: [value]::variables
(get variable with name [name])
(get value of variable with name [name])
delete variable [name]::variables
There are at least 2 reasons why these 3 blocks in particular should be added.
- It would help with one of the most annoying things about scratch (detailed in item 1 here) which is the fact that the variable list can get cluttered very easily (not the returning values thing, although that would be very useful). With the delete variable option this would not be a problem. It allows you to only use certain variables when you need them, and dispose of them later. This would also allow you to have local variables (only available in the current script) by putting a create variable and delete variable block at the start and end of the script.
- It would allow the user to input the name of a variable and use that.
To help you understand this, here is a script that allows the user to add a certain amount to a certain variable:
ask [what amount?] and wait
set [amount v] to (answer)
ask [what variable?] and wait
set [variable v] to (answer)
if <not<[variables v] contains (answer)>> then
say [That variable does not exist!] for (2) secs
else
if <(variable) = [i]> then
change [i v] by (amount)
end
if <(variable) = [i2]> then
change [i2 v] by (amount)
end
end
As you can see, this script requires 2 variables (cluttering the variable space) and quite a lot of code. With these blocks, you could do the same thing like this:
ask [what amount?] and wait
make variable called [amount] value: (answer)::variables
ask [what variable?] and wait
make variable called [variable] value: (answer)::variables
if <not<[variables v] contains (answer)>> then
say [That variable does not exist!] for (2) secs
else
change (get variable with name (get value of variable with name [variable])) by (get value of variable with name [amount])
end
delete variable [variable]::variables
delete variable [name]::variables
Do you see how much simpler and more efficient the last one is compared to the first one? That is why these blocks should be added.
- Wahsp
-
1000+ posts
Make, read, and delete variable blocks.
It's really not that much of a difference (meaning the workaround isn't that complex), I don't really see why this should be implemented. I don't find the variable system cluttered at all, unless you have like 50 variables(and even then, they're automatically organized alphabetically). Do you see how much simpler and more efficient the last one is compared to the first one? That is why these blocks should be added.
- 0037318
-
100+ posts
Make, read, and delete variable blocks.
This is a very small scale example. On a large project with many (20 or more) variables, this becomes much more of a problem.
- Wahsp
-
1000+ posts
Make, read, and delete variable blocks.
Oh I think I see what you mean. So if you need to do 20 of these? This is a very small scale example. On a large project with many (20 or more) variables, this becomes much more of a problem.
if <(variable) = [i]> then
change [i v] by (amount)
end
if <(variable) = [i2]> then
change [i2 v] by (amount) ::variables
end
- FancyFoxy
-
500+ posts
Make, read, and delete variable blocks.
SUPPORT! Especially the block
(read variable [var] :: variables)I made a program that acts on the variable you input, and I have to do
if <(var :: custom) = [gold]> thenIf I could just do this:
set [gold v] to [5]
else
if <(var :: custom) = [gems]> then
set [gems v] to [5]
end
set (read variable (var :: custom) :: variables) to [5]Life would be SOOO much easier.
- Charles12310
-
1000+ posts
Make, read, and delete variable blocks.
I agree that the variables list can sometimes be cluttered that it would require lots of scrolling. Therefore, you got your support.
- RPMO45
-
40 posts
Make, read, and delete variable blocks.
This is a simple suggestion. Basically, you would have 4 new blocks that look like this:make variable called [name] value: [value]::variables
(get variable with name [name])
(get value of variable with name [name])
delete variable [name]::variables
There are at least 2 reasons why these 3 blocks in particular should be added.
- It would help with one of the most annoying things about scratch (detailed in item 1 here) which is the fact that the variable list can get cluttered very easily (not the returning values thing, although that would be very useful). With the delete variable option this would not be a problem. It allows you to only use certain variables when you need them, and dispose of them later. This would also allow you to have local variables (only available in the current script) by putting a create variable and delete variable block at the start and end of the script.
- It would allow the user to input the name of a variable and use that.
To help you understand this, here is a script that allows the user to add a certain amount to a certain variable:ask [what amount?] and wait
set [amount v] to (answer)
ask [what variable?] and wait
set [variable v] to (answer)
if <not<[variables v] contains (answer)>> then
say [That variable does not exist!] for (2) secs
else
if <(variable) = [i]> then
change [i v] by (amount)
end
if <(variable) = [i2]> then
change [i2 v] by (amount)
end
end
As you can see, this script requires 2 variables (cluttering the variable space) and quite a lot of code. With these blocks, you could do the same thing like this:ask [what amount?] and wait
make variable called [amount] value: (answer)::variables
ask [what variable?] and wait
make variable called [variable] value: (answer)::variables
if <not<[variables v] contains (answer)>> then
say [That variable does not exist!] for (2) secs
else
change (get variable with name (get value of variable with name [variable])) by (get value of variable with name [amount])
end
delete variable [variable]::variables
delete variable [name]::variables
Do you see how much simpler and more efficient the last one is compared to the first one? That is why these blocks should be added.
ohh yeah that makes sense! so basically the code creates the variables, and after the script deletes them?
create [variable name] (value)::variables
say (variable name) for (2) secs
change [variable name v] by (5)
say (variable name) for (2) secs
delete [variable name v]::variables
that would be useful for projects stuffed like a thanksgiving turkey with variables
- Gobblesmack
-
100+ posts
Make, read, and delete variable blocks.
complete support, this would be so useful.
- Charles12310
-
1000+ posts
Make, read, and delete variable blocks.
Please do not quote the entire OP if the OP is very long. -snip-
- asivi
-
1000+ posts
Make, read, and delete variable blocks.
a workaround without extra variables(you can use the existent list to store answers)
the variable's hacked block avoid to use a bunch of IF_THEN
Here https://scratch.mit.edu/projects/195166770
the variable's hacked block avoid to use a bunch of IF_THEN
ask [what variable?] and wait
if <not <[VARS v] contains (answer) ?>> then
say [that variable doesn't exist] for (2) secs
else
add (answer) to [VARS v]
ask [change by or new set? c/s] and wait
if <(answer) = [c]> then
ask [change by?] and wait
change (join [] (item (last v) of [VARS v] :: list)) by (answer)
else
ask [set to?] and wait
set (join [] (item (last v) of [VARS v] :: list)) to (answer)
end
delete (last v) of [VARS v]
end
Here https://scratch.mit.edu/projects/195166770
Last edited by asivi (Dec. 23, 2017 14:05:13)
- RPMO45
-
40 posts
Make, read, and delete variable blocks.
Please do not quote the entire OP if the OP is very long. -snip-
well i dont know how to shorten it
- Wahsp
-
1000+ posts
Make, read, and delete variable blocks.
Delete all the text except the quote=username and the /quotePlease do not quote the entire OP if the OP is very long. -snip-
well i dont know how to shorten it
- YubNubEwok
-
1000+ posts
Make, read, and delete variable blocks.
I agree that the variable list can get really cluttered up and it would require extra work/scrolling, so support!
- DaEpikDude
-
1000+ posts
Make, read, and delete variable blocks.
Alternatively, if you're generally responding to the OP instead of a specific part, don't quote it at all. If you don't quote anything it's generally assumed you're talking about the OP.Delete all the text except the quote=username and the /quotePlease do not quote the entire OP if the OP is very long. -snip-
well i dont know how to shorten it
- -KawaiiCode-
-
7 posts
Make, read, and delete variable blocks.
And even with the list. it still does not make the variable. I want these blocks because I want to make a game like Clash of Clans. (Where people can make and attack villages) So it would go something like this:
I know that that is not perfect but it's just an example on what this could be used for.
when green flag clicked
ask [Do You Have A Account?] and wait
if <(answer) = [yes]> then
ask [What is your username?] and wait
if <There is a variable called (answer)-=> then
say (join [Welcome back ] [(answer)]) for (3) secs
else
say [Sorry that account does not exist.] for (2) secs
ask [Please Try Again.] and wait
else
ask [What do you want your username to be?] and wait
if there is a variable called (answer) then
say [Sorry Someone else already chose that username] for (2) secs
else
add variable called (answer) set value to (1)
broadcast [Introduction]
end
I know that that is not perfect but it's just an example on what this could be used for.
- yakedyyak
-
1 post
Make, read, and delete variable blocks.
I thought I had it but it did not work;
I created a variable
any feedback or criticism to my code is appreciated, thanks
I created a variable
when I receive [ v]create clone of [(variable) v]but somehow it did not work, scratch creators, please patch this or create a create variable set value block
set [(variable) v] to [123]
any feedback or criticism to my code is appreciated, thanks
- coder_guy321
-
2 posts
Make, read, and delete variable blocks.
i agree. it is such a good idea and would allow people to do a lot more things!

- LP372
-
1000+ posts
Make, read, and delete variable blocks.
Deleting variables already exists (kinda)