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

#1 2010-07-16 22:47:01

mainiacjoe
Scratcher
Registered: 2010-04-11
Posts: 8

Concatenated Sprite Names in <touching ...> etc.

Suppose you have a dodgeball game with a Hero and 10 balls, names Ball1 through Ball10.  Here is a script in the hero (sorry, I haven't figured out the syntax for putting blocks into forum posts yet; please direct me to a thread on that if you can):

forever
   set ( i ) to ( 1 )
   repeat ( 10 )
      if touching ( join ( "Ball" , i ) )
         change ( hits ) by ( 1 )
      change ( i ) by ( 1 )

The problem is, it takes almost a full second for the for-next loop to run, enough time for a ball to pass through completely.   I discovered this my putting Hero go to mouse-pointer in this forever instead of it own.  I'd wanted to avoid having each ball broadcast if it touches the Hero, since I had the impression that so many messages would slow things down, but apparently not as much as this does.  In any case I was hoping to be able to do this sort of dynamic sprite naming with more arbitrary sets of sprites but perhaps it's not possible without sacrificing performance.  Can Scratch do a fast For...Next style loop or is it always this slow?

Thanks for your help!

- Joe

Offline

 

#2 2010-07-16 22:52:18

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

Re: Concatenated Sprite Names in <touching ...> etc.

Instead of looping it, simply repeat the blocks 10 times. You'll find it to be a lot faster.

Here's why - the loop adds a very large delay to the blocks. For instance,

change x by 10
change x by 10

actually executes a heck of a lot faster than

repeat 2
  change x by 10
end repeat

So there you have it. Enjoy your readily sped-up script!

Unfortunately, with extremely longs scripts this becomes rather impractical - but it's the only way a the moment.

Offline

 

#3 2010-07-16 23:31:56

mainiacjoe
Scratcher
Registered: 2010-04-11
Posts: 8

Re: Concatenated Sprite Names in <touching ...> etc.

Do you mean this:

if touching Ball1
   change hits by 1
if touching Ball2
   change hits by 1
if touching Ball3
   change hits by 1
if touching Ball4
   change hits by 1
if touching Ball5
   change hits by 1
if touching Ball6
   change hits by 1
if touching Ball7
   change hits by 1
if touching Ball8
   change hits by 1
if touching Ball9
   change hits by 1
if touching Ball10
   change hits by 1

Well, that's unfortunately inelegant.  I wish there was a better way, especially to have dynamically changed sprite names.  But if that's what it is, that's what it is.

Thanks,

- Joe

Offline

 

#4 2010-07-16 23:43:22

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

Re: Concatenated Sprite Names in <touching ...> etc.

Unfortunately that is the only effective way to do the task. Of course, you could still use your looping method without the loop, but that serves very little purpose.

Offline

 

#5 2010-07-16 23:43:50

helltank
Scratcher
Registered: 2010-05-21
Posts: 1000+

Re: Concatenated Sprite Names in <touching ...> etc.

Ok, but remember to put forever before that!


Error:Signature could not load. Please wait for an indefinite amount of time, until you realize you're gullible and go off to look for another potentially interesting signature to stare at.

Offline

 

#6 2010-07-17 00:35:08

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

Re: Concatenated Sprite Names in <touching ...> etc.

Actually, you can just use color sensing.


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

Offline

 

#7 2010-07-17 02:51:25

mainiacjoe
Scratcher
Registered: 2010-04-11
Posts: 8

Re: Concatenated Sprite Names in <touching ...> etc.

I tend to avoid color sensing because it restricts you in your backgrounds and causes rude surprises with random pixels tucked in sprites ripped off of sheets.  I honestly don't see why it is so popular around here.

Offline

 

#8 2010-07-17 06:57:05

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

Re: Concatenated Sprite Names in <touching ...> etc.

mainiacjoe wrote:

I tend to avoid color sensing because it restricts you in your backgrounds and causes rude surprises with random pixels tucked in sprites ripped off of sheets.  I honestly don't see why it is so popular around here.

I agree with you 100% - I avoid colour sensing when possible.

Offline

 

#9 2010-07-17 13:03:47

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

Re: Concatenated Sprite Names in <touching ...> etc.

Like all collision methods, color touching 'fits' into some situations better than others. The main reason people don't like it is because they do not make their own sprites so effectively they have no control over the color sensing in general. That explains all of the symptoms mentioned.

Don't get me wrong, I'm not saying it is great. I'm saying nothing is great. What is better, a wrench or a screwdriver? A hammer, a flat head screwdriver or a Phillips head? In my opinion, sprite movement - specifically movement, speed has the biggest impact on collision detection methodology. But then again, I love to use both found and hand drawn sprites.

Last edited by Locomule (2010-07-17 13:04:38)


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

Offline

 

Board footer