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

#1 2012-03-30 20:47:28

jimster
Scratcher
Registered: 2009-10-05
Posts: 13

Help With Variables

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)
end
To see it, follow the link. AGAIN, PLEASE! I NEED HELP

Offline

 

#2 2012-03-30 21:12:03

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

Re: Help With Variables

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.
Now say you want the game to end when the score reaches twenty. You'll need this block, under variables:
(score)
Then put it in this:
When gf clicked
Forever if <(score) > [20]>
Stop all
In 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

 

#3 2012-03-31 09:34:52

jimster
Scratcher
Registered: 2009-10-05
Posts: 13

Re: Help With Variables

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

 

#4 2012-04-01 18:33:04

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: Help With Variables

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

 

#5 2012-04-02 21:10:26

aryabtsev
Scratcher
Registered: 2012-02-05
Posts: 81

Re: Help With Variables

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)
end
I hope this was helpful.

Last edited by aryabtsev (2012-04-02 21:11:39)


http://i.imgur.com/NX7AO.jpg

Offline

 

#6 2012-04-05 17:35:51

jimster
Scratcher
Registered: 2009-10-05
Posts: 13

Re: Help With Variables

Cool, i guess i could do that but isn't there any way to do it with using variables?
:-/

Offline

 

#7 2012-04-05 19:24:50

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: Help With Variables

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

 

#8 2012-04-05 19:38:22

skippito
Scratcher
Registered: 2012-03-17
Posts: 100+

Re: Help With Variables

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

 

#9 2012-04-06 08:55:47

jimster
Scratcher
Registered: 2009-10-05
Posts: 13

Re: Help With Variables

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

 

#10 2012-04-06 23:13:49

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: Help With Variables

Check this out for variables in the Scratch Wiki :
http://wiki.scratch.mit.edu/wiki/Variable


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

Board footer