Classroom Notes: 1.3 Sub-routines
1Q: What is a sub-routine in programming?
A sub-routine is a separate section of code from the main code that performs a specific task.
2Q: Why do programmers use sub-routines in their code?
Programmers use sub-routines to make their code easier to understand and to reduce repetition.
3Q: What does it mean to "define" a sub-routine?
To define a sub-routine means to give the sub-routine a name and write all the instructions that need to be included in it.
4Q: What does it mean to "call" a sub-routine?
Calling a sub-routine means triggering it to respond. A sub-routine can be called more than once, and different algorithms within a program can call the same sub-routine.
5Q: What is the purpose of a variable in programming?
A variable is used to store data that can change.
6Q: Give two examples of how variables can be used together in a quiz game.
- A variable can be used for the score to keep track of how many points a player has scored.
- A variable can be used for 'lives' to limit the number of times a player can answer a question incorrectly.
7Q: Can the same variable be used by different sprites in a program?
Yes, two different sprites can use the information stored in a single variable (like the 'answer' variable) in their own separate algorithms.
8Q: How do you create sub-routines in Scratch?
In Scratch, you can create sub-routines using the 'broadcast' and 'receive' blocks. You can also create sub-routines using 'Make a Block', which is similar but allows for more complex uses.
9Q: What is the function of the 'broadcast' block?
To broadcast means to send a message out. In Scratch, using a 'broadcast' block is like sending a signal or message to all the other sprites and scripts in the project.
10Q: How does the 'ask' block work in a Scratch quiz?
The 'ask' block asks the player a question and opens a typing box for them to enter an answer. This answer is then stored in the 'answer' variable.
11Q: What does "initialisation" mean in a Scratch game?
Initialisation means getting everything ready for the start of the game. For example, using blocks to reset a sprite back to the same position each time the green flag is clicked.
12Q: What does the 'Text to Speech' extension do in Scratch?
The 'Text to Speech' extension adds blocks that make your projects talk. It allows you to make blocks speak a sentence, change the way a voice sounds, and change the language.
13Q: What does it mean when two objects interrelate?
Objects that interrelate are connected so that each object has an effect on, or depends on, the other.
14Q: How can multiple algorithms for different sprites interrelate in Scratch?
Multiple algorithms for sprites can interrelate through sub-routines. For example, one sprite can use a 'broadcast' block to call a sub-routine that makes a completely different sprite perform an action, like a dance move.