Вы находитесь на странице: 1из 14

How to merge two modules

into one bigger project

A tutorial for using the Scratch Module Library

Yuan, yuandong84@yahoo.com 1
Step by Step Overview

Step 1 Know functionalities.

Step 2 Import all modules.

Step 3 Relocate broadcasts and “scene”.

Step 4 House cleaning.

Step 5 Test, test, test!

Yuan, yuandong84@yahoo.com 2
Let’s Do An Example!

We will merge these two modules together.

To follow this example, download these two modules.


m-effects-grow
http://scratch.mit.edu/projects/biy-modules/1446989
m-voice-recognition
http://scratch.mit.edu/projects/biy-modules/1449171
Yuan, yuandong84@yahoo.com 3
Step 1 Know functionalities.

Run each module and read the splash screen, know how each module
starts and stops. Notice if one module is incompatible with another.
(Conflicts on input/output, hardware requirements, etc.)

m-effects-grow is a module that displays a


title frame growing to the front of the
screen. One can stop the module by
pressing “space” key.

m-voice-recognition is a module that uses input


voice loudness to detect number of syllables
(one or two) and plays different music
according to detected result. This module can
be stopped by “space” key pressing.

Yuan, yuandong84@yahoo.com 4
Step 2 Import all modules.
Open one of the modules to be in the bigger project, and go to
“Files\import project” and select all the other modules into this file.

In this example, we will open the m-effects-grow module and import


the m-voice-recognition module.

It has been reported that sometimes you could loose the comments in an
imported project. If this happens, redo the “import” step or just copy
the text of the comments from that original module.
Yuan, yuandong84@yahoo.com 5
Step 2 Import all modules.

Save the file in a new name!

In this example, we will name the bigger project “t-merge-


grow-voice” (“t” is for “test”).

Yuan, yuandong84@yahoo.com 6
Step 3 Relocate broadcasts and “scene”.

Decide the order you want to have the modules to run in. (Assume
that all the modules are running in series, not parallel.)
Go to “stage” and modify the code.

Guidelines:

The module splash screen should not show in a bigger project;

When green flag is clicked, one and only one module starts;

Operations between modules (scenes):


“stop-last-scene” signal sent,
“scene” changed to “next-scene”,
“start-next-scene” signal sent;

The “scene” should be set to be the value that only enables


the current scene (module).

Yuan, yuandong84@yahoo.com 7
Step 3 Relocate broadcasts and “scene”.
In this example, we will let m-effects-grow go first, and m-voice-
recognition next. Here are the changes we need to make to the script
in “stage”.
Starting of the first module:

Connecting of two modules:

Yuan, yuandong84@yahoo.com 8
Step 3 Relocate broadcasts and “scene”.
End of the project:

We have assumed in this example that the two modules are running
one after another. But sometimes we would like to have two
modules running at the same time (e.g. audio and video).
Now how would you adjust the broadcast signals and “scene”
variable changes in the “stage” and/or in individual module sprites
so that more than one module can run in parallel in the bigger
project?

Yuan, yuandong84@yahoo.com 9
Step 4 House cleaning.

Read through the code, especially in the “stage”.


Delete the unnecessary code and backgrounds.

In this example, these are the code we will throw away from the “stage”.

Yuan, yuandong84@yahoo.com 10
Step 4 House cleaning.
Go to “Backgrounds” of “stage”. Delete all the “biy splash” backgrounds.

If you have backgrounds imported from different module stages


that have a same name, Scratch will add a number to the name to
differentiate them. Make sure you adjust the background
switching accordingly.

Yuan, yuandong84@yahoo.com 11
Step 4 House cleaning.
Other possible changes:

Check if more than one module have variables with the same name
but mean different things. Make adjustments accordingly.
......

Would this step be eliminated by making variables local when possible?

Yuan, yuandong84@yahoo.com 12
Step 5 Test, test, test!
Now hit the green flag and see how it goes.

A checking list:

Is there any piece of code in an individual module running


when the “scene” variable is not directed to this module?
If there is, find out why and fix it!

If timer is used (especially when used in more than one


modules), is it working (being reset and recorded)
properly? If it isn’t, find out why and fix it!

Is there any conflict of operation of broadcast signals,


variables, sensing, looks in the project? If there is, find
out why and fix it!
……

Don’t know why or how to fix it? Contact the people who made
those modules. Their contact information is in the splash
screen of the individual modules.
Yuan, yuandong84@yahoo.com 13
Great job!
When you are done with testing the functionalities, it’s time to be
creative and have fun!

Change the graphics to your taste.

Play with the parameters in the projects.

Add other modules or functions to your project.

Now it looks like your project!

Thank you very much for reading this tutorial with us.
Have a question or suggestion? Please contact
yuandong84@yahoo.com.
For more tutorials and information on the project, check
http://build-it-yourself.com/biy-projects/proj-scratch-
templates/index-scratch-templates.html.
Yuan, yuandong84@yahoo.com 14

Вам также может понравиться