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

#1 2010-05-18 17:20:30

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Another "If Touching Color" question... (detection issue)

Think Bejewelled.
http://scratch.mit.edu/projects/infinitum3d/1032442

For example, I have seven squares in a line. When two squares of the same color are touching, I want to be able to click one and have BOTH disappear. I thought about using BROADCAST, and that worked, but it took away ALL the same color squares, not just the ones I clicked...

As an alternative, I could use a sprite (with Ghost effect) as a 'highlighter'. I would need that sprite to detect only if it's touching two matching colors.

Short of hard-coding each combo (not efficient), I can't use:: if NOT 'touching color' 'AND' NOT 'touching color' for each of the color combos. (see below)

Anyone know of a project that has done this, or does anyone have any ideas?

Thanks!

<if><<  << <not>  <touching color[]>   >>   <and>  <<  <not>  <touching color[]>  >>  >>

Last edited by infinitum3d (2010-05-18 17:28:09)

Offline

 

#2 2010-05-18 17:50:17

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Re: Another "If Touching Color" question... (detection issue)

http://scratch.mit.edu/projects/infinitum3d/1059655

I hard-coded it for a project by HARAKOU. I had to stack a bunch of NOT touching color X into an AND operator.

This works for BLUE/BLUE detection only, but there has to be a better way. NOTE: It doesn't do anything other than show that BLUE/BLUE has been detected.

Ideas, suggestions, flames encouraged!!!

wink

Last edited by infinitum3d (2010-05-18 17:51:02)

Offline

 

#3 2010-05-18 19:12:15

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Re: Another "If Touching Color" question... (detection issue)

http://scratch.mit.edu/projects/infinitum3d/1059811

I've hard-coded it for all 6 colors now. It will accurately detect when the Selector is on MATCHING squares. It will stamp between MATCHING squares only.  The STAMP doesn't move as the squares do. This is just a test of "Color Detection".  And it works.


http://scratch.mit.edu/projects/infinitum3d/1059811

Offline

 

#4 2010-05-18 19:38:48

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Another "If Touching Color" question... (detection issue)

Okay, so like I was saying in the original project, this does work. (Sorta) I think it should probably work on the non-visual level. So the detection and changes should be in the lists, then the changes would just be updated by the box sprite. I think I already said this in previous comment replies, but there could be a variable that goes from item to item and checks for matches.
[blocks]
<if> Item i of list whatever=Item  (( i <-> 1 )) of list whatever
delete Item i of list whatever
delete Item  (( i <-> 1 )) of list whatever
<end>
[/blocks]
Original Project: Swap Em's

Last edited by Harakou (2010-05-18 19:49:36)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#5 2010-05-18 20:21:50

AmoebaMan
Scratcher
Registered: 2009-01-26
Posts: 500+

Re: Another "If Touching Color" question... (detection issue)

make one end of the sensor one color, then the other end another color.  then use the <color [clr] is touching [clr]?> block.


http://i942.photobucket.com/albums/ad269/RyanScathe/AmoebaMan.png

Offline

 

#6 2010-05-19 16:49:05

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Re: Another "If Touching Color" question... (detection issue)

OK Harakou! Have you tried it out? I agree that it would seem to be better programming if the detection occurred behind the scenes through code/script.

I'm not a talented enough programmer to help with lists. Sorry.






Why did the chicken cross the road?

Last edited by infinitum3d (2010-05-19 16:49:24)

Offline

 

#7 2010-05-19 19:49:30

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Another "If Touching Color" question... (detection issue)

Argh! I know how I can do this, but going across lists is going to require a lot of hard-coding, which will be a real pain. If only Scratch supported two-dimensional arrays. It would make this so much easier! (Hint hint)

Last edited by Harakou (2010-06-09 17:58:27)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#8 2010-06-17 23:31:24

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Another "If Touching Color" question... (detection issue)

Okay, so I've managed to get back to this project. I don't know if you've made any progress on it. Sorry I haven't posted in quite a while.  sad

Thanks to Paddle2see, I have a way to simulate a matrix. It's actually really simple; I wish I had thought of it. All I need to do is have a list, the length of which equals the number of rows times the number of items in each row the actual matrix would have. So if there were 10 items in each row, Item 6 of row 4 = item 36 in the list. ((Total items in rows before the containing row = 30) + (row item# = 6) = 36)

I redesigned the entire game so that it works on the single list concept; thanks to that, the scripts are now dramatically shorter.  big_smile

So now I can continue with the actual match sensing of the project. It might take awhile depending on how many snags I hit. It's definitely going to be more complex than that other script I posted. I'll try to keep you updated.

Last edited by Harakou (2010-06-17 23:46:03)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

Board footer