Pages: 1
Topic closed
How do you use variables is there an easeir way to use them? <change{ }by( <set{ }to( <{ }>
Offline
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)
Offline
hmnwilson's post is a pretty good overview. Check out the Scratch Wiki Article for more info.
Last edited by Harakou (2010-09-24 22:37:37)
Offline
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.
Offline
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
Offline
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
Topic closed
Pages: 1