This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.
  • Index
  •  » FAQ
  •  » Question on variables

#51 2011-07-26 09:56:34

samuel2k10
New Scratcher
Registered: 2010-12-14
Posts: 1

Re: Question on variables

can someone help me im trying to change my variable by 1 when my sprite is on a different costume.What scripts should I use

Offline

 

#52 2011-07-31 09:34:58

juliabrookek
Scratcher
Registered: 2011-07-18
Posts: 100+

Re: Question on variables

<when green flag clicked>First of all I only know how to do it with global variables, but anyways: If you havent changed the names of the costumes, they should be like "costume1", "costume2", etc:
so you can clearly see the Costume #. Next, there is a little block in Looks ( I think the type of block is a reporter)that says Costume #.
So here is an example of the blocks you'd need for an alien game or something where every time you hit a spacecraft you get 10 pts. This would be a script for the spacecraft, which would have 2 costumes, a regular costume and a blown-up one:
[blocks]<when green flag clicked>[/blocks]
[blocks],<if><<(costume #  <=> 2 )[/blocks]
[blocks]<change{variable}by( 10[/blocks]
[blocks]<end>[/blocks]
(This MAY not look good, it's my 1st time using blocks in the forum.)
You get the idea. When green flag clicked, if costume # = 2, change score by 10.
Which means:if it is in its blown-up costume, you get 10 pts.



Hope this helps!  big_smile


smile http://dragcave.net/image/rgNE5.gif smile

Offline

 

#53 2011-07-31 09:38:35

juliabrookek
Scratcher
Registered: 2011-07-18
Posts: 100+

Re: Question on variables

Wait... Why does it say "when green flag clicked" at the beginning of my last post...
I never put one there!  sad


smile http://dragcave.net/image/rgNE5.gif smile

Offline

 

#54 2011-11-07 12:12:00

Mokko
Scratcher
Registered: 2011-08-14
Posts: 2

Re: Question on variables

This stuff is great! Also, variables can be used as a color or position of a sprite. Take my BETA game for example, it uses variables to change color of a sprite. The variables are changed by cheat codes.

Offline

 

#55 2011-12-15 00:02:53

PaperMario123
Scratcher
Registered: 2011-11-25
Posts: 500+

Re: Question on variables

Variables are Scratch's way of remembering different numbers, digits, values or key combos for a while. Basically, if you set variable A to on, then it'll stay as "on" until it is changed. This is useful for C blocks (like If ___), and making Scratch be able to ask multiple questions, and save answers to all those questions, not just the first one.


http://i.picasion.com/pic46/52268c4a041cced4c8ed97cc7468f869.gif

Offline

 

#56 2012-02-03 22:27:10

Mokat
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: Question on variables

A variable is just what it sounds like. It varies.  tongue 
For the example, let's name the variable "Score."
Let's pretend that you are making a maze game. Whenever you get to the next level, you want to get 10 points.
You do this:

 change [score v] by (1) 
The possibilities for using variables are infinite. What I would recommend is to look at the example projects that use variables and look at how they use them.


http://www.eggcave.com/egg/977371.pnghttp://www.eggcave.com/egg/977376.pnghttp://www.eggcave.com/egg/1005291.pnghttp://www.eggcave.com/egg/996745.png

Offline

 

#57 2012-02-14 10:49:28

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Question on variables

Aarone32 wrote:

Is there a site where I can find some php programming tutorials?...I guess there are a lot more useful information about variable to be found there too.
Thanks
please post here if someone finds such a resource

w3schools


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#58 2012-02-14 10:52:00

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Question on variables

User52 wrote:

Hey i saw this topic and thought i could post my question here. i cant post a topic yet idk why. anyway, i'm making a pokemon simulator with advance damage calculation, but when i tst it, part of the equation turns red. i thought it could be because i dont have parentheses () but i dont know how to add them. help please?

maybe you divided by 0.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#59 2012-03-26 08:02:08

jasmine_neale4
New Scratcher
Registered: 2012-03-26
Posts: 1

Re: Question on variables

hey guys  smile
i was wondering... how do you make a time variable?

please answer soon and dont make the answer to complex!

xoxo love you all!

jasmine  smile

Offline

 

#60 2012-04-25 13:26:53

Cheese-Dragon
Scratcher
Registered: 2012-04-05
Posts: 3

Re: Question on variables

Hello, I am still new to Scratch. In Tech class, we have to create a game called "MadLibs."
I am not sure if we are able to put the variables in places that suits us best. For example, I have some 'fill-ins' that I want the variables to stay in place. But, whenever I open this game the next day, the variables will be out of place.
This is the game: http://scratch.mit.edu/projects/Cheese-Dragon/2494777
It is not finished. Thanks for hearing me out. And if you can help, thank you very much!

Offline

 

#61 2012-06-20 14:20:43

confetticannon
Scratcher
Registered: 2012-06-15
Posts: 5

Re: Question on variables

well if your making a game you think this,

<scratchblocks>
when gf clicked
forever
  wait until <touching [? v]>
  change [lives v] by [-1]
end
</scratchblocks>

no its like this.

 when gf clicked
forever
  wait until <touching [? v]>
  change [lives v] by [-1]
  repeat (5) times
    show
    wait (.2)
    hide
  end

when gf clicked
wait until <(lives) = (0)
hide
stop all
variables are bridges that connect scripts.  smile

Offline

 

#62 2012-11-16 11:42:05

hisneilness
New Scratcher
Registered: 2012-11-16
Posts: 1

Re: Question on variables

Forgive me if this has been answered already, I'm new Scratch and to this site.
I know you can get variables to stay where you've put them if you make them visible. The problem is they then show up on the opening screen. Please can someone tell me if there is a way round this?

Offline

 

#63 2013-04-07 15:23:07

dermo555
New Scratcher
Registered: 2013-04-07
Posts: 1

Re: Question on variables

How do i display the percentage size of my sprite on the screen as if it were a variable?

Offline

 
  • Index
  •  » FAQ
  •  » Question on variables

Board footer