This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-06 16:19:22

joletole
Scratcher
Registered: 2011-02-20
Posts: 1000+

The Variables

Hey guys,

So can someone give a paragraph explaining what the variables (the orange blocks) are.
I don't quite understand what they are

Thanks.

Last edited by joletole (2012-03-06 16:19:57)

Offline

 

#2 2012-03-06 16:24:34

Luke121
Scratcher
Registered: 2008-07-14
Posts: 1000+

Re: The Variables

joletole wrote:

Hey guys,

So can someone give a paragraph explaining what the variables (the orange blocks) are.
I don't quite understand what they are

Thanks.

Explaining really won't help, but I'll try.


In essence, they are anything.


http://bit.ly/IlVuB5
Sorry PF, too lazy to make my own!  tongue

Offline

 

#3 2012-03-06 16:32:59

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: The Variables

Variables are a way to store numbers or words.  When you create a variable and give it a name, you have created a place in the computer that can remember things for you.  You use the name to get at the contents of it (kind of like your home address gets you to your mailbox).  You can change the contents using the "Set Variable to" block. 

So what do we use variables for?  Well, lots of things, but these are the typical uses:

1) To remember something that happened in one part of the program for use later in the program. 

2) To communicate between different sprites (usually by making the variables "For all sprites" meaning all sprites can see their values and change them)

3) To make it so that you can set a value one place...and then use it in many places, like the speed of a sprite.

Make a few and play around...you'll figure it out pretty quickly  smile

Oh, and here's a gallery with a couple of projects on variables and lists that you might find helpful.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#4 2012-03-06 16:36:41

CheeseMunchy
Scratcher
Registered: 2008-10-13
Posts: 1000+

Re: The Variables

Paddle2See wrote:

Variables are a way to store numbers or words.  When you create a variable and give it a name, you have created a place in the computer that can remember things for you.  You use the name to get at the contents of it (kind of like your home address gets you to your mailbox).  You can change the contents using the "Set Variable to" block. 

So what do we use variables for?  Well, lots of things, but these are the typical uses:

1) To remember something that happened in one part of the program for use later in the program. 

2) To communicate between different sprites (usually by making the variables "For all sprites" meaning all sprites can see their values and change them)

3) To make it so that you can set a value one place...and then use it in many places, like the speed of a sprite.

Make a few and play around...you'll figure it out pretty quickly  smile

Oh, and here's a gallery with a couple of projects on variables and lists that you might find helpful.

Perfect description.  big_smile


6418,

Offline

 

#5 2012-03-06 16:36:46

joletole
Scratcher
Registered: 2011-02-20
Posts: 1000+

Re: The Variables

Paddle2See wrote:

Variables are a way to store numbers or words.  When you create a variable and give it a name, you have created a place in the computer that can remember things for you.  You use the name to get at the contents of it (kind of like your home address gets you to your mailbox).  You can change the contents using the "Set Variable to" block. 

So what do we use variables for?  Well, lots of things, but these are the typical uses:

1) To remember something that happened in one part of the program for use later in the program. 

2) To communicate between different sprites (usually by making the variables "For all sprites" meaning all sprites can see their values and change them)

3) To make it so that you can set a value one place...and then use it in many places, like the speed of a sprite.

Make a few and play around...you'll figure it out pretty quickly  smile

Thanks! (and did you see that comment I left on one of your projects)

Offline

 

#6 2012-03-06 16:43:33

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: The Variables

To put it simply, a variable is something which can store a value (whether it be the score, number of lives, or the player's name), and is used within the project (for calculations, or on the stage by having a variable display with the checkbox next to the variable).

In math, you may have learned (or will probably learn soon) about variables. Let's say we have a variable named "x". It can be any number we want. We don't know it's value. However, let's also say we are given this equation: x + 2 = 5. When we add 2 to x, we have to get 5. What could x be? It has to be 3! 3 + 2 = 5 (So it's sort of like a puzzle!) In Scratch, it has a similar role, but we don't have to do any puzzle solving - we just use them to hold values, like scores.

As a brief example for how to use variables, let's look at this example, with the variable "score".

when gf clicked
set [score v] to [0] //The score goes back to 0 each time you play.
forever
if <touching [coin v]?>
change [score v] by [1] //The score increases when you get a coin!

when I receive [game over v] //This tells you your score.
say (join [Your score was ] (join (score) [. Good job!]))
This is just the beginning. Variables can be used together and in a wide variety of ways. Play around yourself by experimenting, and looking at sample projects! For an in-depth explanation about variables, read this article on the Scratch Wiki.

Last edited by Lucario621 (2012-03-06 16:44:28)


http://i.imgur.com/WBkM2QQ.png

Offline

 

#7 2012-03-06 16:55:04

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: The Variables

Lucario621 wrote:

To put it simply, a variable is something which can store a value (whether it be the score, number of lives, or the player's name), and is used within the project (for calculations, or on the stage by having a variable display with the checkbox next to the variable).

In math, you may have learned (or will probably learn soon) about variables. Let's say we have a variable named "x". It can be any number we want. We don't know it's value. However, let's also say we are given this equation: x + 2 = 5. When we add 2 to x, we have to get 5. What could x be? It has to be 3! 3 + 2 = 5 (So it's sort of like a puzzle!) In Scratch, it has a similar role, but we don't have to do any puzzle solving - we just use them to hold values, like scores.

As a brief example for how to use variables, let's look at this example, with the variable "score".

when gf clicked
set [score v] to [0] //The score goes back to 0 each time you play.
forever
if <touching [coin v]?>
change [score v] by [1] //The score increases when you get a coin!

when I receive [game over v] //This tells you your score.
say (join [Your score was ] (join (score) [. Good job!]))
This is just the beginning. Variables can be used together and in a wide variety of ways. Play around yourself by experimenting, and looking at sample projects! For an in-depth explanation about variables, read this article on the Scratch Wiki.

Nice examples!


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer