Discuss Scratch

0037318
Scratcher
100+ 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.
  1. 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.
  2. 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
Scratcher
1000+ posts

Make, read, and delete variable blocks.

0037318 wrote:

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.
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).
0037318
Scratcher
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
Scratcher
1000+ posts

Make, read, and delete variable blocks.

0037318 wrote:

This is a very small scale example. On a large project with many (20 or more) variables, this becomes much more of a problem.
Oh I think I see what you mean. So if you need to do 20 of these?

0037318 wrote:

if <(variable) = [i]> then 
change [i v] by (amount)
end
if <(variable) = [i2]> then
change [i2 v] by (amount) ::variables
end
FancyFoxy
Scratcher
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]> then
set [gold v] to [5]
else
if <(var :: custom) = [gems]> then
set [gems v] to [5]
end
If I could just do this:
set (read variable (var :: custom) :: variables) to [5]
Life would be SOOO much easier.
Charles12310
Scratcher
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.
awsome_guy_360
Scratcher
1000+ posts

Make, read, and delete variable blocks.

Bump
RPMO45
Scratcher
40 posts

Make, read, and delete variable blocks.

0037318 wrote:

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.
  1. 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.
  2. 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
Scratcher
100+ posts

Make, read, and delete variable blocks.

complete support, this would be so useful.
Charles12310
Scratcher
1000+ posts

Make, read, and delete variable blocks.

RPMO45 wrote:

-snip-
Please do not quote the entire OP if the OP is very long.
asivi
Scratcher
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

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
Scratcher
40 posts

Make, read, and delete variable blocks.

Charles12310 wrote:

RPMO45 wrote:

-snip-
Please do not quote the entire OP if the OP is very long.

well i dont know how to shorten it
Wahsp
Scratcher
1000+ posts

Make, read, and delete variable blocks.

RPMO45 wrote:

Charles12310 wrote:

RPMO45 wrote:

-snip-
Please do not quote the entire OP if the OP is very long.

well i dont know how to shorten it
Delete all the text except the quote=username and the /quote
YubNubEwok
Scratcher
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
Scratcher
1000+ posts

Make, read, and delete variable blocks.

Wahsp wrote:

RPMO45 wrote:

Charles12310 wrote:

RPMO45 wrote:

-snip-
Please do not quote the entire OP if the OP is very long.

well i dont know how to shorten it
Delete all the text except the quote=username and the /quote
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.
-KawaiiCode-
Scratcher
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:

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
New Scratcher
1 post

Make, read, and delete variable blocks.

I thought I had it but it did not work;

I created a variable
when I receive [ v]create clone of [(variable) v]
set [(variable) v] to [123]
but somehow it did not work, scratch creators, please patch this or create a create variable set value block
any feedback or criticism to my code is appreciated, thanks
LumberBartek
Scratcher
1 post

Make, read, and delete variable blocks.

Bump
coder_guy321
Scratcher
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
Scratcher
1000+ posts

Make, read, and delete variable blocks.

Deleting variables already exists (kinda)

Powered by DjangoBB