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

#1 2010-01-11 08:24:09

jnylund
Scratcher
Registered: 2010-01-11
Posts: 3

inheritance multiple sprites sharing same code

Hi, I am learning scratch so I can teach the kids programming, one question I have after playing for a while, is there a way to share code across sprites?

For example my son is making a game with a bouncing object, and at the bottom he has a bunch of fruit salad, he wants to make a noise (or change points) when the object touches the fruit salad. But there are like 10 fruit salad sprites, so he would have to write the if touching loop 10 times. Couldn't figure out a way to make or condition or something like this, in this case.

thanks
Joel

Offline

 

#2 2010-01-11 08:27:53

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: inheritance multiple sprites sharing same code

No no there is a way not inheritence but the way is broadcast means u can do like
if touching ground(let ground be name of object ground)
broadcast touch

now in a single sprite
do this
when i recieve touch
play sound bounce


thats it its done that way well kinda calling a function in C++
anyways its very bad that he will have to write the loop 10 times u can always drag and drop code in all sprites for ease though
anyways for somewhat advanced user can use the lists for that to do with same code
or
use BYOB ( a mod of scratch that allows to create u ur own blocks but lacks sharing on website function)u can get it here http://scratch.mit.edu/forums/viewtopic.php?id=10887
using that u can share blocks(code in multiple sprites)

Last edited by fanofcena (2010-01-11 08:35:02)


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

Board footer