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
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
The image above shows my previous attempts that have failed.
Last edited by colorfusion (2010-07-15 15:15:28)
Offline
"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
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)
Offline
Are you sure any means a random one? I'm pretty sure it doesn't...
Offline
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)
Offline
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
Offline
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
"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
http://scratch.mit.edu/projects/colorfusion/1195608
Offline
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.![]()
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.
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.
Offline
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.
Offline
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
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)
Offline
"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