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

#1 2010-09-24 21:45:58

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

How do you use variables is there an easeir way to use them?

How do you use variables is there an easeir way to use them? <change{  }by(  <set{  }to(  <{  }>


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#2 2010-09-24 22:27:45

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: How do you use variables is there an easeir way to use them?

A variable is basically just a value, and have many uses. For example, you know some games keep score? Well, the score is stored in a variable. Same with lives, time, and pretty much anything else you can think of. Programming wouldn't be the same without variables.

Using variables is really easy. The "set ____ to [ ]" block will change the variable to whatever you want. The "change ____ by [ ]" block will make the variable change by a certain amount, as long as the variable is a number.

Making things happen when a variable is really easy, too. Just do this (and sorry, I have to use the forum blocks right now):

<when green flag clicked>
<forever>
<if><( <{ score }> <=> 10 )>
  <broadcast[ You win!
<end>
<end>[/blocks]

That would make it so that you win the game when the score = 10.

Anyway, that's the quick explanation. Remember, just reply if you don't understand something.

Last edited by hmnwilson (2010-09-24 22:29:11)


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

#3 2010-09-24 22:37:16

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: How do you use variables is there an easeir way to use them?

hmnwilson's post is a pretty good overview. Check out the Scratch Wiki Article for more info.  smile

Last edited by Harakou (2010-09-24 22:37:37)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#4 2010-09-24 22:38:40

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: How do you use variables is there an easeir way to use them?

Yeah, hmnwilson pretty much said it all. Here's an easy way to understand them:

A variable is anything that can be changed or set during a program.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#5 2010-09-24 23:13:26

Jwosty
Scratcher
Registered: 2009-12-19
Posts: 500+

Re: How do you use variables is there an easeir way to use them?

ScratchReallyROCKS wrote:

Yeah, hmnwilson pretty much said it all. Here's an easy way to understand them:

A variable is anything that can be changed or set during a program.

One more thing: A variable is the opposite of a constant


http://i39.tinypic.com/18ert5.png Google it.  smile

Offline

 

#6 2010-09-24 23:17:53

S65
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: How do you use variables is there an easeir way to use them?

Jwosty wrote:

ScratchReallyROCKS wrote:

Yeah, hmnwilson pretty much said it all. Here's an easy way to understand them:

A variable is anything that can be changed or set during a program.

One more thing: A variable is the opposite of a constant

I don't think this really applies to Scratch, because as far as I know it doesn't support constants (unless you just want to make a variable and then never change it...but that's kind of tacky).

But yeah, a variable is anything which you can change/set during a program, as ScratchReallyROCKS said. There are string variables (which store sequences of letters instead of numbers, e.g. "You win!" vs. 49383) and lists (which are basically collections of single variables, to put it simply).

Offline

 

Board footer