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

#1 2007-05-27 20:36:29

fandebiao
Scratcher
Registered: 2007-05-15
Posts: 25

Something about Reusablitiy

If you want to make your sprite reusable(which is a very good thing), then follow this guideline:
1.Name of your sprite should be rather unique.  "sprite1" is not a good name.
2.Your sprite should never use the "forever" block, use "repeat until" instead.
3.Use as few global variable as possible.  Use "broadcast" and "when I receive instead". (messages should be unique)
4.If you have to use some global variable, give them very unique names. "score", "a", "x" are bad names.
5.Try to eliminate unnecessary threads such as "when space pressed...". 
6.If there's color collision detection in your program, make the color rather unique.

That's all I got so far, feel free to add more to it.

Offline

 

#2 2007-05-28 03:09:15

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Something about Reusablitiy

I've had trouble exporting sprites from one project and importing them into another.
I had designed my print_decimal and one-sprite-composer programs especially to be sprites that were reusable, but I've only been able to reuse them by importing the whole project.  Importing just the sprite seems to get a sprite that looks ok, but whose scripts don't run---as if the symbol table for the variables had been messed up by the import.

Offline

 

#3 2007-05-28 03:37:52

Canthiar
Scratcher
Registered: 2007-05-16
Posts: 100+

Re: Something about Reusablitiy

Were your sprites using global variables?  I think I had a problem with global variables getting messed up when I was importing sprites that used them.

Offline

 

#4 2007-05-28 04:11:41

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Something about Reusablitiy

Yes, there were three global variables, and it did seem to be the global variables that were messed up.  The globals were used as "parameters" for passing information to the sprite, so there is no way to avoid them.  Importing the whole project got the variables properly, so I think it is a bug in the sprite import/export involving additions to the symbol table.

Offline

 

#5 2007-05-29 18:10:30

tammy
Scratcher
Registered: 2007-03-07
Posts: 57

Re: Something about Reusablitiy

Hi all,

Thanks for this bug report.  I tried to replicate it by exporting and then importing a sprite with global variables, but found that it worked correctly.  Do you know how to replicate this problem?

Thanks,
Tammy

Offline

 

#6 2007-05-29 18:50:58

Canthiar
Scratcher
Registered: 2007-05-16
Posts: 100+

Re: Something about Reusablitiy

Create two sprites, one that writes to a set of global variables and one that reads from the global variables.  If you export and then import the sprite that reads the global variables then the imported one won't read the variables correctly.  I can upload an example if that doesn't help.

Offline

 

#7 2007-05-29 19:27:38

tammy
Scratcher
Registered: 2007-03-07
Posts: 57

Re: Something about Reusablitiy

Thanks, I was able to replicate it.  That was very helpful.  We will fix this bug.

Thanks again,
Tammy

Offline

 

Board footer