HELP ME!!!!! I need a basic tutorial on variables and I can't understand them in Scratch. I've observed other people's projects and I've used those to help me, but when I do it on my own I can't figure it out. I tried doing something simple with variables like increasing and decreasing size constantly in a project. Go to this link: http://scratch.mit.edu/projects/jimster/2435236
help me with this project and then post what you think. PLEASE! I NEED HELP!
This is what my project script looks like:
when gf clicked point in direction (90 v) go to x: (0) y: (0) set size to (100)% show set [Size v] to [100] forever if <<key [space v] pressed?> and <<not<<Size> = [0]>> and <<<Size> = [100]> or <(Size) < [100]>>>> change [Size v] by (-1) change size by (-1) end if <<<<<Size> = [0]> or <(Size) > [0]>> and <not<<Size> = [100]>>> and <key [space v] pressed?>> change [Size v] by (1) change size by (1) endTo see it, follow the link. AGAIN, PLEASE! I NEED HELP
Offline
Variables are used for many purposes. They can help make complex scripts possible, but I'll give you the basics. Variables can be used for keeping score of things, and much more. For example, you can have a variable called "score" for a basketball game. When you start the game, you'll want the score at 0, so you'd do this:
When gf clicked Set [score v] to (0)That would change the score to zero. When a field goal is scored (relating I a basketball game) you would do this:
Change [score v] by (2)That changes the score by 2.
(score)Then put it in this:
When gf clicked Forever if <(score) > [20]> Stop allIn scratch, you can right-click on a block and select help also. The scratch wiki also provides good info. This should help.
Last edited by turkey3 (2012-03-30 21:16:38)
Offline
Thanks for that explanation, but could you demonstrate with my script. I still need some help with that. What I am trying to do in the script is to make a stick figure shrink to
<<Size> = (0)>by decreasing the size from 100%
<change Size by (-1)>and then expanding it by 1 each time
<change Size by (1)>and finally reaching 100%, and then starting all over again. To find this exact script, go to this link and please download it: http://scratch.mit.edu/projects/jimster/2435236
Offline
Variable derives from the word "vary". Vary is to change. A variable is something that changes.
Here is a way variables are used:
when gf clicked go to x: (0) y: (0) point in direction (pick random (-180) to (180)) set [vary v] to (0) forever change [vary v] by (0.1) if <(vary) > (10)> move (vary) steps if on edge, bounce end
Last edited by chanmanpartyman (2012-04-01 18:33:34)
Offline
Hi! I don't think you need variables to do that.
What I would do is:
when flag clicked forever repeat (100) change size by (-1) end repeat (100) change size by (1) endI hope this was helpful.
Last edited by aryabtsev (2012-04-02 21:11:39)
Offline
maybe use this script
when gf clicked set [Size1 v] to [0] forever set size to <<Size1 > + [100]>%
when gf clicked set size to [100]% forever if <key [up arrow v] pressed?> change [Size1 v] by [1] end if <key [down arrow v] pressed?> change [Size1 v] by [-1] end
Offline
Variables are just ways to get scripts to do things. You could make a variable, then use scripts to set it to whatever you want. If it is a certain amount, you can have it make a script do something using operations.
Offline
I thank all of you for your help! But the one who really helped me out was mcvjjmdm with his amazing project at:
http://scratch.mit.edu/projects/mcvjjmdm/2449753
Thanks again! Everyone told me more things about variables then I really knew!
Offline
Check this out for variables in the Scratch Wiki :
http://wiki.scratch.mit.edu/wiki/Variable
Offline