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

#26 2010-07-17 11:00:20

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

Re: Touching an item in a list problem

Wait, what if these sprites stored their distance to the main sprite in a list (prioritized by closeness; closer items are at the top of the list) then the main sprite checks the first item of the list. If it is close enough, then it registers as touching it!  big_smile


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

Offline

 

#27 2010-07-17 11:14:04

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

Re: Touching an item in a list problem

you can make the outline color the same, then use color sensing.

Offline

 

#28 2010-07-17 11:15:13

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

Re: Touching an item in a list problem

Harakou wrote:

Wait, what if these sprites stored their distance to the main sprite in a list (prioritized by closeness; closer items are at the top of the list) then the main sprite checks the first item of the list. If it is close enough, then it registers as touching it!  big_smile

That would be a lot of work. Really, wouldn't just making a long if statement be far more practical?

Offline

 

#29 2010-07-17 11:18:01

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

Re: Touching an item in a list problem

coolstuff wrote:

Harakou wrote:

Wait, what if these sprites stored their distance to the main sprite in a list (prioritized by closeness; closer items are at the top of the list) then the main sprite checks the first item of the list. If it is close enough, then it registers as touching it!  big_smile

That would be a lot of work. Really, wouldn't just making a long if statement be far more practical?

I don't think so. My arm would fall off.

Offline

 

#30 2010-07-17 11:21:16

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

Re: Touching an item in a list problem

What if you made multiple counters? For instance, if there were 2 counters, it would go about twice as fast. In that case, the counters would be started at 1 and 2. At each repeat, it would check to see if it is touching item (counter1) or (counter2) and then each counter would be changed by 2.


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

Offline

 

#31 2010-07-17 11:30:17

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

Re: Touching an item in a list problem

It occured to me that you could try doing something similar to this. It might be a little slow, but it should to the trick.

http://scratch.mit.edu/forums/viewtopic.php?id=40677

Offline

 

#32 2010-07-17 12:44:10

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

Re: Touching an item in a list problem

OK, what if you put the script in the sprites that the main sprite would be touching?

Make each sprite check forever if it (the sprite) is in the list and if it is touching the main sprite. If it is, broadcast something to the main sprite. It should be pretty fast, and not too tedious to make, since the script will be the same for all sprites and can just be duplicated.


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

Offline

 

#33 2010-07-17 12:46:21

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

Re: Touching an item in a list problem

scmb1 wrote:

OK, what if you put the script in the sprites that the main sprite would be touching?

Make each sprite check forever if it (the sprite) is in the list and if it is touching the main sprite. If it is, broadcast something to the main sprite. It should be pretty fast, and not too tedious to make, since the script will be the same for all sprites and can just be duplicated.

That actually makes a lot of sense. I think so far this is your quickest solution.

Of course, if you already have all the sprites made it might take a while to get all the scripts in, but from what I understand the sprites are just about the same. That being the case, you could just delete all of the duplicate sprites and duplicate them.

Offline

 

#34 2010-07-17 13:13:26

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

Re: Touching an item in a list problem

scmb1 wrote:

OK, what if you put the script in the sprites that the main sprite would be touching?

Make each sprite check forever if it (the sprite) is in the list and if it is touching the main sprite. If it is, broadcast something to the main sprite. It should be pretty fast, and not too tedious to make, since the script will be the same for all sprites and can just be duplicated.

Well, I could do that but it would have to be 100 forevers which takes up a lot of memory and 100 variables since broadcast can only start a script and not do something half way through.

Offline

 

#35 2010-07-17 14:24:58

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

Re: Touching an item in a list problem

Can't you make it work the opposite way?  It's just a tiny thing in each of the sprites scripts them...

Do you need a hundred variables?  You'd only need a hundred variables if you wanted to do 100 different things.  Otherwise you can just have one and have it either be set to one when touching the sprite, or changed by one.

Last edited by AtomicBawm3 (2010-07-17 14:27:09)


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

Offline

 

#36 2010-07-18 04:28:07

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

Re: Touching an item in a list problem

"Can't you make it work the opposite way?  It's just a tiny thing in each of the sprites scripts them...

Do you need a hundred variables?  You'd only need a hundred variables if you wanted to do 100 different things.  Otherwise you can just have one and have it either be set to one when touching the sprite, or changed by one."

Most of the sprites either dont have any scripts or don't have forever loops in them.

And I probably will need up to 100 things because thats the size the project is heading for.
I plan to have around 20 different levels and 1 already has 6 sprites.
I have put the sprites in a list, all that I need to do is have a way of sensing if the main sprites is touching any in the list!

Offline

 

#37 2010-07-18 11:03:59

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

Re: Touching an item in a list problem

Do you really need to be checking for every sprite at all times during the game? If not, that would make a list smaller.
If you are planning on having a hundred sprites running around on the screen at the same time... good luck. But wait, you aren't..

"Most of the sprites don't have any scripts or forever loops" so they don't move or do anything? How do they know where to go when you start the game or change levels? Does every level use the same screen? Are all these sprites just decorative and if so, why does the player need to sense collisions with them at all?

You really need to post the project so we can tell what you are trying to do. Guessing is fun and all but not necessarily all that productive and you are wanting results, right? That's what we shoot for in All About Scratch.. no soldier gets left behind on this battlefield!


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

Offline

 

#38 2010-07-18 12:03:26

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

Re: Touching an item in a list problem

OK, I made a project that works pretty quickly. It does require scripts in the non-main sprites, but the are not long and you can mostly just duplicate them. It does not used lots of variables (none, actually). Mine only has 13 sprites, but it will work with any number. The list on "touchable" sprites can be put in any order and have any length and the items can easily change whenever and it will still work.

Does it work for your purpose?


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

Offline

 

#39 2010-07-18 13:15:18

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

Re: Touching an item in a list problem

I cant upload the project at the moment as I am on a non-scratch computer and movement doesn't even work yet.
It needs to sense if it is happening half way through a movement script, so it cant be broadcasts because they can only start scripts.
It also cant be variables because I cant make 100 different variables.
So the scripts to sense need to be inside the main moving sprite.

Most of the sprites just get overlapped with other sprites when they are done with, it saves putting in a lot of scripts, and the ones that do have scripts are mainly just "When I receive next level next costume" that cant have a forever loop put in them.

I don't think there is any way around doing it, I just need to know how to sense if a sprite is touching an item in a list from its own scripts.

Offline

 

#40 2010-07-18 13:24:33

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

Re: Touching an item in a list problem

colorfusion wrote:

I cant upload the project at the moment as I am on a non-scratch computer and movement doesn't even work yet.
It needs to sense if it is happening half way through a movement script, so it cant be broadcasts because they can only start scripts.
It also cant be variables because I cant make 100 different variables.
So the scripts to sense need to be inside the main moving sprite.

Most of the sprites just get overlapped with other sprites when they are done with, it saves putting in a lot of scripts, and the ones that do have scripts are mainly just "When I receive next level next costume" that cant have a forever loop put in them.

I don't think there is any way around doing it, I just need to know how to sense if a sprite is touching an item in a list from its own scripts.

Did you look at the project I linked to?

It does not use broadcasts or variables to sense and it can work partway through a script. The one broadcast it does use is just so the other sprites don't start changing the "touching" list before it is created. If you don't want to use broadcasts for some reason, just replace the "When I receive___" block in all of the non-main sprites with "When flagged clicked" and start the scripts off with a "wait (.5) secs" block.

Does that make sense? From what you've told us about your project, I'm pretty sure it should work.

Last edited by scmb1 (2010-07-18 13:37:20)


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

Offline

 

#41 2010-07-18 13:59:40

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

Re: Touching an item in a list problem

scmb1 wrote:

colorfusion wrote:

I cant upload the project at the moment as I am on a non-scratch computer and movement doesn't even work yet.
It needs to sense if it is happening half way through a movement script, so it cant be broadcasts because they can only start scripts.
It also cant be variables because I cant make 100 different variables.
So the scripts to sense need to be inside the main moving sprite.

Most of the sprites just get overlapped with other sprites when they are done with, it saves putting in a lot of scripts, and the ones that do have scripts are mainly just "When I receive next level next costume" that cant have a forever loop put in them.

I don't think there is any way around doing it, I just need to know how to sense if a sprite is touching an item in a list from its own scripts.

Did you look at the project I linked to?

It does not use broadcasts or variables to sense and it can work partway through a script. The one broadcast it does use is just so the other sprites don't start changing the "touching" list before it is created. If you don't want to use broadcasts for some reason, just replace the "When I receive___" block in all of the non-main sprites with "When flagged clicked" and start the scripts off with a "wait (.5) secs" block.

Does that make sense? From what you've told us about your project, I'm pretty sure it should work.

Although I cant see since I cant open it when downloaded at the moment that looks like it uses a forever loop in each sprite which would probably drive my project way over the memory limit.

Offline

 

#42 2010-07-18 14:11:42

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

Re: Touching an item in a list problem

colorfusion wrote:

scmb1 wrote:

colorfusion wrote:

I cant upload the project at the moment as I am on a non-scratch computer and movement doesn't even work yet.
It needs to sense if it is happening half way through a movement script, so it cant be broadcasts because they can only start scripts.
It also cant be variables because I cant make 100 different variables.
So the scripts to sense need to be inside the main moving sprite.

Most of the sprites just get overlapped with other sprites when they are done with, it saves putting in a lot of scripts, and the ones that do have scripts are mainly just "When I receive next level next costume" that cant have a forever loop put in them.

I don't think there is any way around doing it, I just need to know how to sense if a sprite is touching an item in a list from its own scripts.

Did you look at the project I linked to?

It does not use broadcasts or variables to sense and it can work partway through a script. The one broadcast it does use is just so the other sprites don't start changing the "touching" list before it is created. If you don't want to use broadcasts for some reason, just replace the "When I receive___" block in all of the non-main sprites with "When flagged clicked" and start the scripts off with a "wait (.5) secs" block.

Does that make sense? From what you've told us about your project, I'm pretty sure it should work.

Although I cant see since I cant open it when downloaded at the moment that looks like it uses a forever loop in each sprite which would probably drive my project way over the memory limit.

Ah... I suppose you could just use a repeat block instead, but I don't know- does that use less memory?


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

Offline

 

#43 2010-07-20 00:02:33

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

Re: Touching an item in a list problem

Just instead of using a repeat block, make it set a variable to 1, then duplicate this script as many times as need: if touching (join(sprite,#)) then replace item(#) of(list) with(yes) else, replace item(#) of(list) with(no) change(#) by(1).


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

Offline

 

Board footer