a.Create and write down an algorithm to solve this problem. You might like to use the idea above, or an alternative of your own.
(10 marks)
b.Create a when[space]key_pressed script to implement your algorithm. Depending on your algorithm and the way in which you choose to implement it, you may also decide to have a when_green_flag_clicked script.
(11 marks)
I'm using OUBuild that saves as .sb2 (I'm not sure what version this is)
Assistant
Certainly! Since you’re working with OUBuild, which is very similar to Scratch (.sb2 file format), I will walk you through both:
a) Writing an algorithm in pseudocode for a general problem (since you didn't specify the problem, I’ll assume you want a sample problem to solve with key presses, e.g., moving a sprite with arrow keys).
b) Writing the "when [key] key pressed" block-based script to implement the algorithm, along with an optional when green flag clicked script to initialize variables or setup the stage.
a) Algorithm (Pseudocode)
Problem example: Move a sprite left, right, up, or down using arrow keys, and reset position when the green flag is clicked.
code
Algorithm MoveSprite
1. When the green flag is clicked
a. Set the sprite's position to the center of the stage (x=0, y=0)
b. Set the sprite's direction to 0 (facing right)
2. When the left arrow key is pressed
a. Change x position by -10 (move left)
3. When the right arrow key is pressed
a. Change x position by +10 (move right)
4. When the up arrow key is pressed
a. Change y position by +10 (move up)
5. When the down arrow key is pressed
a. Change y position by -10 (move down)
b) Scratch/OUBuild Script Implementation
When green flag clicked:
Use the block when green flag clicked
Use go to x: 0 y: 0 to reset the sprite position
(Optional) Use point in direction 90 (which faces right in Scratch environment)
When [key] key pressed:
Create one when key pressed block for each arrow key
Inside each block, move the sprite accordingly
Example script blocks for OUBuild
Script 1: Initialization
code
when green flag clicked
go to x: 0 y: 0
point in direction 90
Script 2: Move Left
code
when [left arrow] key pressed
change x by -10
Script 3: Move Right
code
when [right arrow] key pressed
change x by 10
Script 4: Move Up
code
when [up arrow] key pressed
change y by 10
Script 5: Move Down
code
when [down arrow] key pressed
change y by -10
Notes for your submission:
Write the algorithm clearly in pseudocode or stepwise instructions, as shown above.
For the code/scripts, you could write them down as the Scratch blocks or explain them in script form.
If you want to be more advanced, you could have a single keypress event with a decision structure, but since OUBuild/Scratch have one key pressed block per key, multiple scripts are standard.
Save your project as an .sb2 file.
If your original problem is different from this (e.g., counting, drawing, a game, etc.), please provide more details, and I’ll tailor the algorithm and script precisely for that problem.
Hope this helps! Let me know if you want me to adapt this for your specific problem.