Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help understanding variables
- Dirkthedaring
-
New Scratcher
5 posts
Help understanding variables
Hi there Scratch forum,
I am having some trouble understanding what variables are used for. Would anyone be able to give me a brief explanation or point me to a tutorial?
Thank you very much,
Dirk the daring
I am having some trouble understanding what variables are used for. Would anyone be able to give me a brief explanation or point me to a tutorial?
Thank you very much,
Dirk the daring
- pufferfish101007
-
Scratcher
100+ posts
Help understanding variables
Right, so basically variables are used to store values so they can be used later. So, let's say you're making a project that adds two numbers. A bit basic, but oh well. So, you're going to ask the viewer for a number with
To do this, you're going to do
Now lets say you want to add 1 to that. So you could make a new variable and set that to the previous answer+1, or you could do
That's about it.
Hope this helped!
when green flag clicked // or whatever you want to doSo this stores the user's answer in the reporter block
ask (what is the first number you want to add?) ::sensing
answer::sensingBut when you ask a new question, it's going to change that value to the next answer. So you want to set that value as a variable.
To do this, you're going to do
set (first number) to (answer::sensing)::variablesThen you're going to do it all again, but with the second number:
ask (what is the second number you want to add?) ::sensingThen you're going to add them together using the addition block, set that as a variable and slot that in a ‘say…’ block, and you're done.
set (second number) to (answer::sensing)::variables
Now lets say you want to add 1 to that. So you could make a new variable and set that to the previous answer+1, or you could do
change (answer) by (1)::variablesAnd then you can say it.
That's about it.
Hope this helped!
- SparshG
-
Scratcher
500+ posts
Help understanding variables
https://en.scratch-wiki.info/wiki/Variable
https://en.scratch-wiki.info/wiki/Variables_Tutorial
I had made a short tutorial on variables using the above two links if you would like to see: https://scratch.mit.edu/projects/150991939/
(Not advertising, but many people found the tutorial helpful…)
https://en.scratch-wiki.info/wiki/Variables_Tutorial
I had made a short tutorial on variables using the above two links if you would like to see: https://scratch.mit.edu/projects/150991939/
(Not advertising, but many people found the tutorial helpful…)
- Oumuamua
-
Scratcher
1000+ posts
Help understanding variables
A variable is a changeable value recorded in Scratch's memory. Variables can only hold one value at a time, unlike lists. These values can be either numbers or strings — any text.
To learn more about click the link below
https://en.scratch-wiki.info/wiki/Variable
https://en.scratch-wiki.info/wiki/Variables_Tutorial
Last edited by Oumuamua (May 6, 2020 11:24:18)
- arvepro3579
-
Scratcher
100+ posts
Help understanding variables
You can set them to numbers. Here is an idea:
move (this variable) stepsIf the variable is 5, it will move 5 steps.
set [this variable v] to [5]
- deck26
-
Scratcher
1000+ posts
Help understanding variables
You can set them to numbers. Here is an idea:But if you're helping perhaps not showing the blocks in the wrong order would be sensible!move (this variable) stepsIf the variable is 5, it will move 5 steps.
set [this variable v] to [5]
- Dirkthedaring
-
New Scratcher
5 posts
Help understanding variables
Thank you all very much for your responses to my variables query.
I think I understand them now - and I have some good resources to return to now, so thank you again!
This is a wonderfully helpful community
I think I understand them now - and I have some good resources to return to now, so thank you again!
This is a wonderfully helpful community

- Discussion Forums
- » Help with Scripts
-
» Help understanding variables





