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

#1 2012-06-28 17:12:13

CHOMPYCHEESE
Scratcher
Registered: 2012-06-11
Posts: 9

Detecting a group of sprites.

Hey there!

I am making a Knots and Crosses game, and I have finished the scripts for X and O placement... But, I now need to figure out how to detect that I have three thingymabobs in a row...
I have set a lot of invisible lines in the background, so when they get the que, they sense if they have three in a row.

THE PROBLEM: I need a simple script, as there are five Xs and four Os and I want to detect only three. Instead of saying ->

when gf clicked
forever if (touching [sprite 1] and [sprite 2] and [sprite 3])
  broadcast [I got 3 in a row]
end 
This scrpit only allows for detection of three of five of the sprites... SO, is there a script that is able to say... 'If touching three of possible Sprites one, two, three, four, five' instead of me listing all the possible combinations for me to write in a long script.

thanks

Offline

 

#2 2012-06-28 17:23:18

bertdog
Scratcher
Registered: 2012-06-12
Posts: 100+

Re: Detecting a group of sprites.

well there are the operater blocks you could try but I don't know any other way.


"Losers quit when they are tired,Winners quit when they are done." smile http://blocks.scratchr.org/API.php?user=bertdog&action=onlineStatus

Offline

 

#3 2012-06-28 17:24:44

CHOMPYCHEESE
Scratcher
Registered: 2012-06-11
Posts: 9

Re: Detecting a group of sprites.

But is there a way to detect a group of three from a group of sprites?

Offline

 

#4 2012-06-28 17:38:06

Zparx
Scratcher
Registered: 2011-03-23
Posts: 500+

Re: Detecting a group of sprites.

YES, THERE IS A WAY TO DO THIS!

I have done this in one of my games, and here is how you do it:

First you make a list and put in it all of the sprites you wish to detect. Put the actual names of the sprites in the list. For example, if your sprite is named "Enemy1", type it exactly like that for the list, even with capital letters.

Okay so you've got your list, now do this:

make a variable and call it whatever.

when gf clicked
set [Sprite v] to (0)
Forever
change [Sprite v] by (1)
if <(Sprite) > (length of [list of sprites to detect v]) >
set [Sprite v] to (0)
end
Now make another variable called "Temporary". It doesn't have to be called that, but you'll understand why I said to do so in a minute.

Keep the above code running, then put THIS code in the sprite you want to be able to detect the sprites:


when gf clicked
Forever
if <touching (Sprite) ?>
set [Temporary v] to (Sprite) //this way it doesn't lose focus                                                                           
Do whatever here, but make sure it's associated with toucing "Temporary"!                                         

Hope I helped! Good luck!


http://images3.wikia.nocookie.net/__cb20101119183412/halo/images/4/43/Hero2.png
^ My rank on Halo: Reach :3

Offline

 

#5 2012-06-28 17:59:10

CHOMPYCHEESE
Scratcher
Registered: 2012-06-11
Posts: 9

Re: Detecting a group of sprites.

This is rather confusing, sorry, amatuer scripter is my name...

Is there a way to put sprites into a list??

Offline

 

#6 2012-06-28 18:04:19

Zparx
Scratcher
Registered: 2011-03-23
Posts: 500+

Re: Detecting a group of sprites.

CHOMPYCHEESE wrote:

This is rather confusing, sorry, amatuer scripter is my name...

Is there a way to put sprites into a list??

Okay try this:

with the repeating code of "Sprite constantly changing, you could do:

set [Temporary v] to (Join [Sprite](Sprite))
Does THAT help any?


http://images3.wikia.nocookie.net/__cb20101119183412/halo/images/4/43/Hero2.png
^ My rank on Halo: Reach :3

Offline

 

#7 2012-06-28 18:39:05

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Detecting a group of sprites.

Name your crosses "c1", "c2", etc.

set [c v] to (0)
set [j v] to (0)
repeat (5)
change [c v] by (1)
if<touching(join [c](c))?>
change [j v] by (1)
end
end
if<(j) > (2)>
broadcast [crosses win v]
end

Last edited by MoreGamesNow (2012-06-28 18:40:20)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

Board footer