Do not repeat yourself
ReadingYour own words
Your game has a row of jumpers. Each one has its own copy of the same script. Say you want them all to wait a little longer between jumps.
You would have to open every jumper and change every copy. Miss one, and that jumper is out of step. With four jumpers it is a bore. With forty it is a trap.
The rule
Coders have a rule for this: do not repeat yourself. Write a thing once, give it a name, and use the name wherever you need it. Then a change in one place changes it everywhere.
This chapter has two ways to do that.
| Tool | What it is | What it saves |
|---|---|---|
| Your own word | A name for some steps, inside one script. | Writing the same steps twice in a script. |
| A family | One script that many characters share. | Copying a script onto every character. |
Your own word
You know words like jump and hop. You can add words of your own. This script teaches a slime the word dance.
learn to dance
hop left 1 block
jump
hop right 1 block
end| Line | What it does |
|---|---|
learn to dance | Starts a new word, called dance. |
| The steps inside | What the word means. |
end | The word stops here. |
After that, dance is a step like any other. Coders call a word like this a function.
Finish this section
Tick Finished reading at the bottom of the page. Then press Next to teach a slime to dance.

