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

#1 2010-07-15 15:07:25

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Touching an item in a list problem

I need a sprite to sense if it is touching any of the items in a really long list and it doesn't have time to do it the count variable way.

I have tried <touching (Item [any] of [list]> But it turns out "Any" actually means "A random item in the list" and is just the way that it is phrased that made me think it would work.

The list will need to have up to 100 items so I cant really do "<touching sprite 1 or <touching sprite 2 or <touching..."

And yes it does really need to be in a list, since things will be removed, added, changed, and more things will be put in the list by me.

Maybe for the next version of scratch they can add (Item [Any] of [List]) and replace the current any with (Item [Random] of [list])

Offline

 

#2 2010-07-15 15:12:01

dav09
Scratcher
Registered: 2009-03-25
Posts: 1000+

Re: Touching an item in a list problem

its basically like this

<when green flag clicked>
<if>
<touching[item () of list]
do what ever u want. im not sure if this will work


i see ur problem but im not sure
u could set item as any

Last edited by dav09 (2010-07-15 15:17:57)

Offline

 

#3 2010-07-15 15:12:41

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: Touching an item in a list problem

http://i32.tinypic.com/2vw72bm.jpg

The image above shows my previous attempts that have failed.

Last edited by colorfusion (2010-07-15 15:15:28)

Offline

 

#4 2010-07-15 15:13:43

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: Touching an item in a list problem

"its basically like this

<touching[item () of list]
do what ever u want. im not sure if this will work"


As I said, the list could be around 100 items long, that only works for one thing.

Offline

 

#5 2010-07-15 20:26:26

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Touching an item in a list problem

Ok, here you go. This only works if you use trigger variables to make sure that each different routine is completed in order. This is basically colorfusion's idea 2 sped up.

This is in loop order...
1-the list "Touching" deletes all of its items
2- Each sprite will do its own check to see if it is touching the player. If it is, it adds its sprite number to the list (sprite #50 adds "50", etc)
3-The player sprite checks to see if the list has any items
if not, presumably most of the time, it skips ahead
4-If the list is longer than 0 items, set a loop to the number of items in the list.
One at a time, start with (presuming you have 100 items) if list item (loop #) is <50 else if <25 else if <12 etc. This way you can reduce the entire process to A. not even running most of the time and B. narrowing down what is touching faster.
5-do whatever else then restart the loop

The biggest drawback I foresee with this system depends on how many items are simultaneously touching the player and how often? PS. have you actually made a project with over 100 sprites in it yet?

edit: Another idea.. all items that share the same attribute, like items that simply block player movement like a tree stump, a table, a big rock, etc can be lumped together into groups. This will speed up searching because now you can say If item < biggest group item and item > smallest group item then block player movement, or whatever.

Last edited by Locomule (2010-07-15 21:27:31)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#6 2010-07-16 00:32:30

juststickman
Scratcher
Registered: 2009-05-31
Posts: 1000+

Re: Touching an item in a list problem

Are you sure any means a random one? I'm pretty sure it doesn't...


http://is.gd/iBQi2 Add grob to your sig and help with world dominiation!http://is.gd/iBQ9Q                                                             Hey guys, we're seriously naming our team bob?

Offline

 

#7 2010-07-16 01:10:29

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Touching an item in a list problem

I'm talking about the second method, there are three shown in the picture. The second one doesn't use the Any (and no it doesn't mean random) but is the one labeled "needs to work faster"

Last edited by Locomule (2010-07-16 01:11:11)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#8 2010-07-16 11:56:33

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: Touching an item in a list problem

Thanks locomule, but that would still require making a script in each of the up to 100 sprites, I have a list of all of them and I was kind of hoping that it could just sense if it was touching any one of them and do something.

Offline

 

#9 2010-07-16 12:27:24

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

Re: Touching an item in a list problem

It doesn't mean random. It means any. Which it goes through the whole list to detect. Try
it. The item any of list.

It works.


Hai.

Offline

 

#10 2010-07-16 12:30:36

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Touching an item in a list problem


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#11 2010-07-16 12:30:50

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Touching an item in a list problem

fg123 wrote:

It doesn't mean random. It means any. Which it goes through the whole list to detect. Try
it. The item any of list.

It works.

Are you absolutely sure? I'm not on a computer that has Scratch on it right now, but as I recall, the "item (any) of" block is random.

Offline

 

#12 2010-07-16 12:42:30

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

Re: Touching an item in a list problem

soup: And I posted it there too.
stuff: I'll make a project to demonstrate.
It will flash a bit but it will work.


Hai.

Offline

 

#13 2010-07-16 12:45:44

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

Re: Touching an item in a list problem

It only works offline though.  sad
http://scratch.mit.edu/projects/fg123_tests/1195719


Hai.

Offline

 

#14 2010-07-16 13:01:03

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: Touching an item in a list problem

"It only works offline though.   
http://scratch.mit.edu/projects/fg123_tests/1195719"

See its flashing on and off?
Its because the random item changes, it can only be 5 things so 1/5th of the time it will be touching it, but I need mine to work 100% of the time.

It is random, check my newest project if you wana see.

Offline

 

#15 2010-07-16 14:57:59

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Touching an item in a list problem

whoops


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#16 2010-07-16 14:59:08

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Touching an item in a list problem

link the project


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#17 2010-07-16 15:14:49

laser100
Scratcher
Registered: 2009-12-04
Posts: 100+

Re: Touching an item in a list problem

Try " <if touching (bleh)>
blah blah blah."

Neva mind.

Last edited by laser100 (2010-07-16 15:26:36)

Offline

 

#18 2010-07-16 15:30:30

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: Touching an item in a list problem

http://scratch.mit.edu/projects/colorfusion/1195608

Offline

 

#19 2010-07-16 16:13:27

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

Re: Touching an item in a list problem

fg123 wrote:

It doesn't mean random. It means any. Which it goes through the whole list to detect. Try
it. The item any of list.

It works.

It only works offline though.  sad
http://scratch.mit.edu/projects/fg123_tests/1195719

Nah, if you just pull the block (Item any of list) into the script editing window and click on it, it returns a random item of the list. Therefore, the result is the same in this situation.

If it was as you say, it would be inconsistent. The Scratch team would never make a block like that. It would be too confusing for people.  sad

I wish it would be changed to (Item random of list) and the block you're talking about added though; it would be so much easier.


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

 

#20 2010-07-16 16:27:26

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Touching an item in a list problem

I did a little check - turns out fg123 was indeed incorrect. Sorry - I was hoping you were right, too!

You'll have to do one of the many things that Locomule suggested instead  smile

Offline

 

#21 2010-07-16 20:55:05

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Touching an item in a list problem

Ok, now link the actual project  smile


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#22 2010-07-16 21:21:29

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: Touching an item in a list problem

I've found that the (item (any) of [list]) block only works well in turbo mode. I think the only way to make it work in normal mode is to do |wait until <touching [(item (any) of [list]]>|. That way, it actually would have time to check, but it wouldn't take a lot of time either.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#23 2010-07-17 00:21:24

A__B__3__T__E__S__T
Scratcher
Registered: 2010-05-29
Posts: 45

Re: Touching an item in a list problem

If your character it a circle, you could use the distance block, but then again, maybe its not fast enough or it's random.

Offline

 

#24 2010-07-17 00:27:05

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Touching an item in a list problem

Actually, wait, if all your sprites are the same color, than you can just use color sensing!!

The counting method seems to work for me.  How many sprites are you using?

Last edited by AtomicBawm3 (2010-07-17 00:33:29)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#25 2010-07-17 04:14:08

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: Touching an item in a list problem

"Actually, wait, if all your sprites are the same color, than you can just use color sensing!!

The counting method seems to work for me.  How many sprites are you using?"


So far I have 6 sprites, but I only just started the first aura, I plan to make a lot of auras so it could take up to 100 and the counting method would take about 3 seconds every time it moved 2 steps.

The sprites are all different colours, and some are to thin to outline.

Offline

 

Board footer