You can use variables to keep track of how many of something you've done, like your score, how many items you've collected, how many things are left to be done, etc. But you can also use words in variables instead of numbers, like, for example, you could make a variable called "animal", in a pet game, and make some animal sprites. Say there were 3 sprites: a dog, a cat, and a horse. If you clicked the horse, the variable: "animal" would change from "none" to "horse", instead of "1" to "2" or "3" or whatever. There is also a very clever way of using words in variables to type your name, which Paddle2See discovered. Just look at his/her stuff and you'll find the project.
You make a variable called "Uppercase" and a list called "text input". You use this script for typing in letters:
[blocks]<when[ a ]key pressed>[/blocks]
[blocks]<if>[/blocks][blocks]<( [blocks]<{ Uppercase }>[/blocks] <=> 1 )>[/blocks]
add A to text input
[blocks]<else>[blocks]
add a to text input
[blocks]<end>[/blocks]
And this script to for the "Uppercase" variable (which you can add to any sprite) to add uppercase letters whilst typing:
<when[ up arrow ]key pressed>
[blocks]<set{ Uppercase }to( [/blocks] [blocks](( 1 <-> [blocks]<{ Uppercase }>[/blocks] ))[/blocks]
So you can use variables for all sorts of things! I hope this helps you! If it doesn't, just let me know by posting a comment in my topic: "Anyone Need Any Help?" in the All About Scratch section!
Happy Scratch-ing!
Offline
zbs wrote:
Wow, Super Smash Bros. Scratch is REALLY good!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 10/10
Hey zbs, this post of yours doesn't seem to have anything to do with the topic being discussed (Variables). Please put your posts only on related topics. You can also start a new topic if you can't find one. Thanks.
Offline
Variables can also be used to show messages. For example:
[blocks]<when I receive[ play
<if><( <{ level }> <=> 1 )>
<set{ message }to( Get to the door to go to the next level.
<end>
<if><( <{ level }> <=> 2 )>
<set{ message }to( If you touch a spike, then you have to restart the level.
<end>
<if><( <{ level }> <=> 3 )>
<set{ message }to( You need to press buttons to open doors.
<end>
Last edited by floppy_gunk (2009-01-31 03:46:24)
Offline
I am learning that variables play an important part in programming. Assigning variables is a essential way of communicating to the program as to what you want it to do. For instance, if I wanted to keep up with my students' weight using the scratch program, I would use "weight" as the variable.
Offline
a variable like <{ goals scored }>?
Offline
<stop all sounds> <play note( 234231313 )for( 9999999999999999999999 )secs> that is alot
Offline
sonicfan2 is me and has no signiture ok?
Offline
Ok now will i get that signiture
Offline
I've used it for cpus in my game i'm about to upload ( )
<{ X of sprite }>
<{ Y of sprite }>
I would explain cpus but it's another story...
<set{ X of sprite }to(<x position>
Then the enemy
<when green flag clicked>
<forever>
<glide( Number of seconds )secs to x <{ X of sprite }> )y
Y of sprite
sorry if i went off topic there but it included variables about cpus
Offline
piko_12 wrote:
Does anyone knows how 'velocity' variable works ??
its really quite easy. just search for like velocity tutorial. i could show u but some tutorials are easier and faster
Offline
golfer3 wrote:
piko_12 wrote:
Does anyone knows how 'velocity' variable works ??
its really quite easy. just search for like velocity tutorial. i could show u but some tutorials are easier and faster
Thank you, golfer3. Where can i find the tutorial?
Thank you again
Piko_12
Offline
piko_12 wrote:
golfer3 wrote:
piko_12 wrote:
Does anyone knows how 'velocity' variable works ??
its really quite easy. just search for like velocity tutorial. i could show u but some tutorials are easier and faster
Thank you, golfer3. Where can i find the tutorial?
Thank you again![]()
Piko_12
"Velocity" is just the name of a variable, just because it is named velocity doesn't make a difference.
However, if you want to know how to use velocity in one of your games I can help.
Let's start with "Y Velocity":
Using yVelocity will help if you want to make good jumping scripts for your games.
To start this session of testing arrange the stage like this:
If the image doesn't load go to this link: http://img144.imageshack.us/my.php?image=stage.gif
Then in the Cat sprite make this script:
If the image doesn't load go to this link: http://img519.imageshack.us/my.php?image=picture4kef.png
Text of the comment block (if you can't read it):
This is a basic jumping script. We'll start by breaking it down. The first if statement with the set yVelocity to 0 block in it is their so the cat will not fall through the ground. The next if with the set yVelocity to 15 block in it will function if the cat is on the ground and the up arrow is pressed and will make the cat jump.
Out of that set of ifs the change y by yVelocity will make him fall or rise depending on the velocity variable. And the change yVelocity by -1 is gravity.
Remember that you can change the 15 in the;
block to make the cat jump higher!
HERE IS THE LINK TO THE FORUM TOPIC http://scratch.mit.edu/forums/viewtopic.php?id=16077
Last edited by demosthenes (2009-04-20 14:18:51)
Offline
piko_12 wrote:
Does anyone knows how 'velocity' variable works ??
Names of variables are not important. The role of variables is what counts.
velocity refers to speed
Offline
This topic is getting a little all over the place now...
Anyway, as I said, variables can be set to words as well as numbers. You just wouldn't be able to put "if mood=happy" because in the equals block, you can only type numbers, not letters. Variables don't always have to be "if this variable equals this, make this message appear or this screen appear", they can also determine how fast the sprite goes, whether it gets more power or an extra attack move if it reaches a certain score/level, or even what it randomly says or does! Variables are very useful indeed. Your forum topic actually just made me remember that! I haven't used variables in clever ways like that in a while...
Offline
All you need to know about a variable:
1. It is treated as a number. Say we have a variable called pie. We use a block to set Pie to 5. 5 divided by pie is the same as 5 divided by 5.
2. Names don't matter. The name helps you remember it, calling a variable **** is the same as calling it bob.
3. Anything that's not just a number will be treated as 0. Say we set variable bob to pie. bob equals 0.
4. Lists are better. A list is basically a bunch of variables. You can use 1 list instead of 200+ variables in a project. You just need to remember which variable is which number...
5. You can <broadcast[ <{ variable }>
That's pretty much it.
Offline
pokemon_master12 wrote:
Variables are very useful indeed.
Lists are better.
Offline
I need help with variables!
I can't get my Character's broadcasted "Level Up" to be recieved and activate the "Change Level by 1" Variable doodamabob thing.
Offline
.::ADVANCED VARIABLE HELP::.
If you already know how to use variables, you might find these helpful.
If you right click (windows) or ctrl click (mac) on a variable, you a menu will pop up. I has four options.
1. Normal Readout: When you create a variable, this is the default veiw.
2. Large Readout: This is a larger display of the variable, but the variable name is hidden
3. Slider: This creates a slider that a user can change. It shows the name of the variable and the value of the variable. The default range is 0-100
4. Hide: A shortcut that hides the variable
If you change your variable to a slider, a new option appears:
Set Slider Min and Max: If you click this option, a window pops up. You can now set the minimum and maximum. The minium does not have to be 0. Click OK to continue.
Hope that helps
Offline