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

#1 2012-11-06 13:02:46

dharthvader
New Scratcher
Registered: 2012-11-06
Posts: 1

How do I change a variable only when one of my sprites hits another?

I have a program now where you control one sprite and the other one randomly bounces around and you have to avoid it. How do I count the number of times that your user controlled sprite hits the random one? The object of the game is to avoid the other sprite.

Offline

 

#2 2012-11-06 14:44:47

WOLFLOVER458
Scratcher
Registered: 2011-07-31
Posts: 46

Re: How do I change a variable only when one of my sprites hits another?

do a "When [name of sprite] hits [color outlining other sprite]" block. Then put under a  "Change variable by -1" or +1. depending.


Hug yourself! You know your great, you know your amazing! You know it, so HUG YOURSELF! o^.^o

Offline

 

#3 2012-11-06 14:57:47

awesomeness321
Scratcher
Registered: 2012-08-10
Posts: 100+

Re: How do I change a variable only when one of my sprites hits another?

WOLFLOVER458 wrote:

do a "When [name of sprite] hits [color outlining other sprite]"That doesn't exist. I think you mean 'if <touching color [color outlining other sprite]> block. Then put under a  "Change variable by -1" or +1. depending.

Uh, that doesn't exist. I think you mean this:

when gf clicked
forever
if <touching color [color outlining other sprite]?>
change [whatever the variable is called v] by (1)//or -1 if you want it to go down.
But that would only work if the sprite was outlined by 1 color.

Instead, you could use this:
when gf clicked
forever
if <touching [other sprite's name v]?>
change [whatever the variable is called v] by (1)//or -1 if you want it to go down.


My newest project:http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=projects&amp;type=newest&amp;return=image&amp;num=1Color:#30F9A5 I am currently http://blocks.scratchr.org/API.php?user=awesomeness321&amp;action=onlineStatus&amp;type=text

Offline

 

#4 2012-11-06 15:15:29

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: How do I change a variable only when one of my sprites hits another?

awesomeness321 wrote:

WOLFLOVER458 wrote:

do a "When [name of sprite] hits [color outlining other sprite]"That doesn't exist. I think you mean 'if <touching color [color outlining other sprite]> block. Then put under a  "Change variable by -1" or +1. depending.

Uh, that doesn't exist. I think you mean this:

when gf clicked
forever
if <touching color [color outlining other sprite]?>
change [whatever the variable is called v] by (1)//or -1 if you want it to go down.
But that would only work if the sprite was outlined by 1 color.

Instead, you could use this:
when gf clicked
forever
if <touching [other sprite's name v]?>
change [whatever the variable is called v] by (1)//or -1 if you want it to go down.
wait until <not <touching [sprite whatever v] //So it doesn't add more than one each time it touches.

smile


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#5 2012-11-06 15:17:59

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How do I change a variable only when one of my sprites hits another?

mythbusteranimator wrote:

awesomeness321 wrote:

WOLFLOVER458 wrote:

do a "When [name of sprite] hits [color outlining other sprite]"That doesn't exist. I think you mean 'if <touching color [color outlining other sprite]> block. Then put under a  "Change variable by -1" or +1. depending.

Uh, that doesn't exist. I think you mean this:

when gf clicked
forever
if <touching color [color outlining other sprite]?>
change [whatever the variable is called v] by (1)//or -1 if you want it to go down.
But that would only work if the sprite was outlined by 1 color.

Instead, you could use this:
when gf clicked
forever
if <touching [other sprite's name v]?>
change [whatever the variable is called v] by (1)//or -1 if you want it to go down.
wait until <not (touching [sprite whatever v]?)> //So it doesn't add more than one each time it touches.

smile

Fixed.

Last edited by ErnieParke (2012-11-06 15:18:17)


http://i46.tinypic.com/35ismmc.png

Offline

 

#6 2012-11-06 15:30:27

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: How do I change a variable only when one of my sprites hits another?

So to summarize the posts above me, this script would be inserted at the player controlled sprite:

when gf clicked
forever
if <touching [opponentSprite v] ?>
change [points v] by (-1) //or +1
wait until <not<touching [opponentSprite v] ?>>
end
end

Last edited by fg123 (2012-11-06 15:30:41)


Hai.

Offline

 

Board footer