Is there a way for a sprite to know which sprite is the closest to him? I mean, without having to check for every single sprite and then without having to know in advance all sprite names.
I'm thinking of a script associated with a sprite that, once you duplicate the sprite several times, would be able to let the sprite know which sprite is the closest to him.
Offline
That would probably be possible

Offline
You could work the project backwards: Let's say you have a bunch of Target sprites and one Hero sprite. Each Target sprite could compute the distance to the Hero sprite (when requested by a broadcast message) and, if it is smaller than a global variable called Distance, replace that value with a new shortest distance. The target sprite could also update a couple of location variables X_Closest and Y_Closest at the same time. Then, whenever the Hero wanted to know which Target was closest, it would simply send out a message and then head towards X_Closest,Y_Closest. Would that work for what you are trying to do?
Offline
Paddle2See beat me to it. I think his idea is exactly the way I would do it. I was considering doing a simulation once of group behavior of birds (google "Boids" for a good example) and I think that's the way I started to do it.
Offline
chalkmarrow wrote:
Paddle2See beat me to it. I think his idea is exactly the way I would do it. I was considering doing a simulation once of group behavior of birds (google "Boids" for a good example) and I think that's the way I started to do it.
I've been thinking about Boids for quite awhile! Flocking behavior and all that...it would be cool. I haven't made any real progress on it though. Probably shouldn't be hijacking this thread...
Offline
Thanks for replying to this "weird" topic of mine, Paddle2See and Chalkmarrow.
I had thought of the "many-to-one" strategy (as opposed to the "one-to-many" that forces to know in advance the name of all sprites). But what I was thinking in reality is a "many-to-many" search for the closest sprite. In this case I have no hero (or many heroes)
Do you think that this is possible? Or more classical programming instruments (such as arrays or lists) are needed?
I think that a very nice possibility that should seriously considered to be added to Scratch is a "duplicate" command that would allow a sprite to duplicate itself. But allowing this, a sprite cannot know in advance the names of all other spirtes. What do you think?
(btw: why I didn't receive a copy of your replies by email? how do I subscribe to this topic?)
Offline
s_federici wrote:
I think that a very nice possibility that should seriously considered to be added to Scratch is a "duplicate" command that would allow a sprite to duplicate itself. But allowing this, a sprite cannot know in advance the names of all other spirtes. What do you think?
Or also a "duplicate sprite #..." (i.e. the duplication of a given sprite performed by another sprite) could be a nice addition. Even if you could always send a message to the "duplicable" sprite that would decide by itself if it would like to be duplicated. This would make object-orientation safer, I guess.
Offline
I haven't been able to come up with a good solution to the many-to-many problem. I think it would require arrays and sorting to do.
As far as subscribing to this topic, I believe that Andres had to disable Subscribe when they moved to a new server. I don't think that problem is fixed yet.
Offline