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

#1 2012-12-24 18:31:06

luthien
New Scratcher
Registered: 2012-12-24
Posts: 2

Communication between sprites?

Hi everyone,

I am trying to design a memory game.  Basically, I have two of each animals on a grid, and a user is supposed to find paired animals by opening boxes. 

Right now, I have it set up so that when a user clicks on a field, the sprite changes a costume (to that of a cat, for example), broadcasts a message ("cat") meant to be received by the paired sprite, waits for 1 second, and then changes costume back to a green square.  My idea was to set it up so that, when revealed, cat1 communicates to cat 2, and if the user clicks on a field corresponding to cat2, that mouse click will cause both cats to be revealed and remain like that on the screen.

The issue was that in the script for cat1, I cannot find a way to represent mouse click on cat2 (or any other sprite) as an event.

For cat2, I tried to write a script that goes something like this:

     if message "cat'' received and if mouse click on cat2,
     then change costume of cat1 and cat2 to reveal original cat costume.....

I hope I explained well enough what the issue is.  Is there a way to fix this?  Is there a different way to approach the whole design of this game? 

I would appreciate all thoughts.  Thanks so much,
L

Offline

 

#2 2012-12-24 18:51:47

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: Communication between sprites?

This is just an idea, so sorry if it doesn't make sense but...

What if you created a variable for each pair of sprites, incremented it by 1 after it's been clicked, and set it back to 0 after 5 seconds? If the variable is 2, than you have a match.

For example:

when gf clicked
set [cat_clicks v] to (0)
forever
if < (cat_clicks) = [2] > 
broadcast [Cat Match Found! v]
end

when I receive [Cat Clicked v]
change [cat_clicks v] by (1)
wait (5) secs
set [cat_clicks v] to (0)

when [cat1] clicked
broadcast [Cat Clicked v]


when [cat2] clicked
broadcast [Cat Clicked v]  
I'm not 100% sure this would work, but it is something to give a try. If you have lots of sprite pairs you could try a list instead of a bunch of variables.


http://i48.tinypic.com/2z5pqad.png

Offline

 

#3 2012-12-28 17:33:04

luthien
New Scratcher
Registered: 2012-12-24
Posts: 2

Re: Communication between sprites?

Hi scmb1,

Thanks so much for your response -- I did something along the lines of what you had suggested and it worked.  Here is the game:

http://scratch.mit.edu/projects/luthien/3007985

The only issue I could not work out was how to randomly change the positions of each piece after the game is over and the new game is begun.

I would love to hear any suggestions.

Thanks so much,
L

Offline

 

#4 2012-12-28 17:58:20

30-1
Scratcher
Registered: 2012-08-08
Posts: 100+

Re: Communication between sprites?

go to x: (pick random (-46) to (46)) y: (pick random (-30) to (30))
you may have to change those amounts


http://i.imgur.com/ocOya7x.gif
I. Text I Based I Games I

Offline

 

#5 2012-12-31 11:08:00

minecraftpe123
Scratcher
Registered: 2012-11-18
Posts: 100

Re: Communication between sprites?

luthien wrote:

Hi everyone,

I am trying to design a memory game.  Basically, I have two of each animals on a grid, and a user is supposed to find paired animals by opening boxes. 

Right now, I have it set up so that when a user clicks on a field, the sprite changes a costume (to that of a cat, for example), broadcasts a message ("cat") meant to be received by the paired sprite, waits for 1 second, and then changes costume back to a green square.  My idea was to set it up so that, when revealed, cat1 communicates to cat 2, and if the user clicks on a field corresponding to cat2, that mouse click will cause both cats to be revealed and remain like that on the screen.

The issue was that in the script for cat1, I cannot find a way to represent mouse click on cat2 (or any other sprite) as an event.

For cat2, I tried to write a script that goes something like this:

     if message "cat'' received and if mouse click on cat2,
     then change costume of cat1 and cat2 to reveal original cat costume.....

I hope I explained well enough what the issue is.  Is there a way to fix this?  Is there a different way to approach the whole design of this game? 

I would appreciate all thoughts.  Thanks so much,
L

Personally i would use Call statements to allow communication between sprites. I scratch this would be using the broadcasting block so when 1 sprite is ready it can broadcast "ready" then when the other sprite receives "ready" it can then carry one. Hope this helped!

Offline

 

Board footer