Zum Inhalt springen

English:Block-based programming and event-driven design - Computing Year 7

Aus MOOCsWiki Staging
aiMOOC-Siegel aiMOOC

Block-based programming and event-driven design - Computing Year 7

QR-Code



Introduction

Scratch editor as a starting point for an original event-driven scene
Build the separate Controller/Gate project using the specified event handlers, shared variable and message. The screenshot is editor context, not the completed project.

Create a two-sprite scene with keyboard and click/tap actions, coordinated messages and a clear reset. Trace the exact event rules, compare their logic with Python and collect honest build-and-test evidence. Year 7 allocation is editorial within England’s KS3 Computing pathway.


Specify an event-driven scene for its users

An event-driven project waits for events and runs the matching handlers. A key press, a click, the green flag or a received message can start a script. The vertical order within one stack matters, but the physical position of separate stacks on the editing canvas is not a reliable global running order. A block language still expresses executable logic; snapping blocks together does not remove the need for a specification and tests.

Our original project is an exploratory two-sprite scene. A Controller sprite accepts either a space-key press or a click/tap. Each completed action increases a shared whole-number count by one. A Gate sprite displays Keep exploring until the count reaches three, then Gate open. The green flag resets the count to zero and refreshes the display. These invented project points are not MOOCwiki learning points, real assessment data or a judgement of the user.

The Scratch 3.0 editor with a sprite and block categories
This unchanged Commons screenshot shows the Scratch editor and a separate short sound example. It is not the original Controller/Gate project or evidence that our project has been built in that editor. Identify the Stage, sprite list and script workspace, then construct the original stacks from the instructions below.

Choose or draw two simple original sprites and rename them Controller and Gate. Give the Controller a visible label or costume that makes its click action clear. No copied commercial characters, camera, microphone, cloud variables or public account is needed. Work in a school-approved editor, save locally where available and keep any real learner names out of the example.

Create count as a variable for all sprites, so both the Controller and Gate read the same stored value. The Controller changes it; the Gate reads it to decide what to say. A sprite-only variable with the same visible name can be a different value, so two independently created count variables are not a substitute for deliberate shared scope. Keep one clearly named shared variable for this project.

Before coding, write the input and output contract. The input sequence starts after the green-flag reset has completed; test one action at a time, allowing its update to finish. Count remains a non-negative integer because the only changes are reset to zero and increase by one. Unknown event names in the later paper/Python model do nothing. We are not claiming arbitrary overlapping scripts, held-key repeat rates or timed animations behave as a single atomic transaction.

Observe how Scratch Team uses a sprite click to drive a changing project. This original publisher's clicker tutorial offers inspiration and extension, not the specification of our separate two-sprite scene. Our written stacks, trace and native activities provide a complete alternative without the external player. Original: Scratch Team, How to Make a Clicker Game in Scratch | Tutorial. The written explanations and native tasks work without sound or the external player.

Collect a tiny user requirement before adding effects: someone using a touch screen should have a visible tappable route, and someone using a keyboard should have a clear space-key route. Keep the Gate's feedback as readable text rather than only a colour or sound. Test both inputs with the same expected count and message. A decorative animation is useful only if it does not hide the result or make the project harder to control.



Build communicating handlers and control the update order

A message coordinates scripts, while a variable carries the project data. Create a broadcast message named refresh. It tells the Gate when to update, but it does not automatically include the count as a data payload. The Gate obtains that value by reading the explicitly shared variable. If a different project needs additional data, its storage and interpretation must be designed rather than assumed to travel inside the message name.

Build the following stacks on the named sprites. The text is a readable inventory of Scratch blocks and their nesting, not Python or a script to paste into an editor. Use the corresponding Events, Variables, My Blocks, Control, Operators and Looks blocks. Make a custom block called record action on the Controller; its purpose is to avoid keeping two copies of the same count-update logic.

CONTROLLER: when green flag clicked
    set [count] to (0)
    broadcast [refresh] and wait

CONTROLLER: when [space] key pressed
    record action

CONTROLLER: when this sprite clicked
    record action

CONTROLLER: define record action
    change [count] by (1)
    broadcast [refresh] and wait
GATE: when I receive [refresh]
    if (count > 2) then
        say [Gate open]
    else
        say [Keep exploring]
    end

The Controller has three event handlers: green flag, space key and sprite click. Both action handlers call the same custom block. Reset is deliberately different: set the count to zero before sending refresh. Do not put independent initialisation on the Gate and assume separate green-flag stacks run in a convenient order. One ordered reset-and-refresh route makes the intended data dependency explicit.

In record action, change count before broadcasting refresh. If refresh were sent first, the receiver could display the previous count's status. The Gate's receive handler checks the new count and says its result. Use the ordinary say block that leaves readable text, rather than a timed version for this core exercise. Extra delays or overlapping event handlers would create additional timing questions and require new tests.

Scratch supplies a greater-than comparison block. For the integer counts generated here, count greater than two means the same threshold as count at least three. These expressions are not equivalent for every possible number: a fractional value of two and a half is greater than two but is not at least three. Our whole-count invariant matters; do not transfer the equivalence to arbitrary decimals without checking the domain.

A plain broadcast starts matching receiving scripts and lets the sender continue; broadcast and wait waits for the triggered receiving scripts to finish before the sender continues. That does not mean the entire project stops or that every independent event is prevented from starting. With multiple receivers, do not rely on an undocumented order between them. The core project has one Gate receive handler and deliberately finite processing.

Separate number blocks as an analogy for stored values and instructions
ajay_suresh’s unchanged photograph illustrates discrete symbols and values only. A physical arrangement does not execute a Scratch handler, pass a broadcast payload or prove the Controller/Gate trace. Use the actual stack order and shared-variable rule as the project specification.

Use meaningful message names and inspect the exact dropdown selection. A refresh sender cannot trigger a receiver listening for another message. A custom block is also different from a broadcast: it names a reusable procedure on that sprite, whereas a broadcast can start matching receive scripts elsewhere. The same idea of modularity appears in textual functions, but the mechanisms and data-sharing rules are not identical.

Debug one responsibility at a time. Show count while testing. If it changes but the Gate text does not, check the broadcast name, receiver and variable scope. If it increases twice for a single intended action, look for duplicated handlers before changing the threshold. If it never resets, inspect whether reset uses set to zero rather than change by zero. A named expected trace is more informative than repeatedly clicking until the scene looks right.



Trace events, compare Python and test the project

Trace the project as a sequence of completed events, then compare representations. Start with a green-flag reset. For each event, record the old count, the responsible handler, the next count and the Gate text. Our original seven-event sequence includes reset, both action routes and an unconfigured event. It deliberately treats each event as completed before the next; it is not a claim about simultaneous inputs or animation scheduling.

Completed event Next count Gate text Reason
flag 0 Keep exploring Reset and refresh
click 1 Keep exploring Add one and refresh
space 2 Keep exploring Add one and refresh
click 3 Gate open Add one and refresh
other 3 Gate open No configured action
flag 0 Keep exploring Reset and refresh
space 1 Keep exploring Add one and refresh

After click, space and click, count reaches three and the Gate opens. An unconfigured other event leaves both count and text unchanged. The next flag resets the count to zero and the displayed result to Keep exploring. The final space gives one. A reset that changes only the variable but never refreshes the receiver can leave a stale Gate open message; test the visible output as well as the stored number.

Python code in a textual programming environment
Weal2019’s unchanged photograph provides a second representation context. Its matrix/graph program is unrelated to this event model. The short independently written Python functions below, rather than code copied from the photograph, define the actual comparison.

The original Python functions below model the same completed-event logic. They do not install key listeners, draw a sprite or execute Scratch blocks. Calling event_step once processes one supplied event-name string; the caller must retain the returned count before the next call. The returned flag says whether a named event was handled in this model, not whether a learner answered a question correctly.

def display_status(count):
    if type(count) is not int or not count >= 0:
        raise ValueError("Use a non-negative integer count")
    if count >= 3:
        return "Gate open"
    return "Keep exploring"


def event_step(count, event):
    status = display_status(count)
    if type(event) is not str:
        raise ValueError("Use an event-name string")
    if event == "flag":
        return 0, "Keep exploring", True
    if event in ("space", "click"):
        count = count + 1
        return count, display_status(count), True
    return count, status, False

The Python selection uses count at least three, equivalent to the Scratch greater-than-two block only for the non-negative integer count contract. display_status rejects negative, non-integer and Boolean counts deliberately. event_step rejects a non-string event; other unrecognised strings are ignored with handled False. These choices make the comparison's boundaries explicit rather than relying on accidental coercion between text and number types.

For example event_step with count two and click returns three, Gate open and True. Feeding the old two into every later call would fail to preserve evolving state. A separate loop may process a supplied list of events in order, but defining these functions does not automatically connect them to the operating system's keyboard or the Scratch editor.

Stored data across representations: Scratch Team — What Are Variables and Lists in Scratch? (Part 1)| Tutorial. Identify where a variable keeps information between events, and explain why the message name alone is not the numerical data. Compare with Python parameters and returned values. The written scope explanation and original trace work without the video.

Test count zero, two and three, reset from an already open state, one click, one key event and an unconfigured event. Then test both actual input routes in your own Scratch project. Record expected and observed count and text. The supplied Python logic comparison was actually executed against independent event rules, including complete short event sequences. Those checks are not a claim that a Scratch project file was executed or that a learner has demonstrated practical competence.

Extend for a known user rather than merely adding more effects. One group may need larger click targets, another a quieter scene with sound off, and another a clearer written instruction. Combine a locally created original backdrop with the programmed scene, record a simple anonymous usability checklist and explain one revision. Do not upload identifiable recordings or personal data as a default way to prove the project.

For advanced reasoning, introduce two receiving sprites and predict which parts can safely run independently. If the sender must wait until both finish, use broadcast and wait, but still avoid assuming a fixed receiver order. If later handlers yield or interact with shared state, add a deliberate busy/ready design or a controlled event queue and test overlapping requests. That is a new requirement, not a property automatically guaranteed by the original small scene.

Submit the saved original project if you actually built it, screenshots showing both sprite scripts, a completed trace, tests of keyboard and click/tap input, and the Python logic comparison if you ran it. Mark a paper walkthrough as a walkthrough. This course and the neighbouring Python course contribute to the broader KS3 multi-language and creative-project portfolio; they do not alone certify the complete statutory programme or every user's device.



Interactive Tasks


Quiz: Test Your Knowledge

What starts a configured event handler? (The matching event such as a click, key press or received message) (!The vertical position of its stack among all other stacks) (!Any unrelated message with a different name) (!A screenshot being saved by another user)



Why is count made available to all sprites here? (The Controller changes it and the Gate reads the same stored value) (!Every sprite-only variable with the same name is automatically shared) (!A broadcast secretly transports every local variable) (!Variables only store costume colours)



What does the refresh message carry automatically in this design? (A trigger name, with count read from explicitly shared storage) (!The complete numerical count as an automatic payload) (!A private learner record and an official grade) (!An instruction to reset every variable in every project)



Which order follows the original record action specification? (Increase count by one, then broadcast refresh and wait) (!Broadcast first, then hope the receiver sees the later value) (!Reset count on every action before any increase) (!Only move the sprite without changing or sharing any state)



Why do both action handlers call one custom block? (It keeps the shared update procedure in one place) (!It guarantees no other script can ever run) (!It sends a message to every project on the internet) (!It removes the need to test either input route)



When is count greater than two equivalent to count at least three here? (For the stipulated integer counts, including the boundary three) (!For every real number including two and a half) (!Only when the count variable stores a word) (!Never, even for the integers zero, one, two and three)



What does broadcast and wait guarantee for its sender? (The sender continues after the triggered receiving scripts finish) (!It imposes a fixed documented order on every receiver) (!It disables every other event in the entire project) (!It automatically adds a numerical data payload)



What follows from the complete original event trace? (The final count is one and the Gate says Keep exploring) (!The final count is four because the reset is ignored) (!The Gate stays open after every later reset) (!The unconfigured event adds one automatically)



What does the supplied Python comparison actually do? (Process a supplied event value and return updated model state) (!Execute the Scratch sprite project and render its costumes) (!Install a real keyboard listener just by defining a function) (!Prove that every touch-screen input has been tested)



Which evidence supports the practical project objective? (A saved original project, actual input tests and clearly labelled results) (!A claim that a paper trace is identical to actual execution) (!Only a copied screenshot of the Scratch editor) (!A high fictional counter presented as official learning points)





Memory Game

Event An occurrence that can start a matching handler
Handler The script configured to respond to a named event
Broadcast A message trigger sent to matching receiving scripts
Shared variable One stored value deliberately available across sprites
Custom block A named reusable procedure on its sprite
Trace A record of state and outputs across a specified sequence





Drag and Drop

The Controller receives the green flag Set count to zero before refreshing the display
The Controller receives a click after reset Increase the count to one and refresh
The count changes but the Gate text does not Check the message name, receiver and variable scope
A single intended action adds two Look for duplicate handlers before changing the threshold
A later project requires overlapping timed events Specify coordination and new tests rather than assuming atomic behaviour





Crossword Puzzle

EVENT What occurrence can begin a configured script?
HANDLER What script responds to a matching event?
BROADCAST What sends a named trigger to receiving scripts?
VARIABLE What stores the count between completed events?
SPRITE What project object owns the Controller scripts?
TRACE What record follows changing state and visible outputs?





LearningApps

Optional extra practice. Choose an appropriate activity with your teacher. If the external collection is unavailable, use the native activities and independent tasks in this course.


Cloze Text

Complete the explanation.
An event starts a matching

. Both input routes use one

block. The count variable is deliberately

across sprites. Change the count

refreshing the display. A broadcast name does not automatically contain a data

. Integer count greater than two opens the Gate at

. A green flag resets the count to

. The original seven-event trace finishes at count

. The Python function returns a new

. Paper reasoning is distinct from actual

.



Open Tasks


Easy

  1. Name events: Identify the three Controller events and the Gate receive event.
  2. Set up scope: Explain why the original project needs one shared count rather than two sprite-only counts.
  3. Build the reset: Place the reset and refresh blocks in their specified order.
  4. Trace to three: Follow a click, space and click after reset, showing count and Gate text.


Standard

  1. Use both inputs: Actually test keyboard and click/tap routes if you build the project, recording expected and observed results.
  2. Diagnose stale output: Explain how count can reset while a stale Gate open message remains, and repair the update route.
  3. Compare thresholds: Explain the integer-domain equivalence and use two and a half as a counterexample outside that domain.
  4. Compare control flow: Identify the event trigger, reusable procedure and shared state in Scratch and their explicit Python counterparts.


Advanced

  1. Add a user requirement: Revise a target size, text instruction or sound option using a known anonymous usability need.
  2. Coordinate receivers: Design a two-receiver extension and distinguish sender waiting from assumed receiver order.
  3. Plan overlapping inputs: Specify a busy/ready or queued-event extension and name tests for rejected or delayed requests.
  4. Evaluate practical evidence: Submit an original build and actual tests where available; clearly separate Python model execution, Scratch execution and paper traces.



Learning Check

  1. Event and handler design: Explain why block position is not a global schedule.
  2. Shared data and messages: Explain what the receiving sprite reads.
  3. Threshold and input domain: Justify the Scratch and Python comparison.
  4. Complete original trace: Carry the state through a reset and an ignored event.
  5. Waiting and comparison limits: Explain what is and is not guaranteed.
  6. Debugging and extension: Make a justified change for a user and test it.


Worked checks and assessment guidance

  1. The green flag, space key and Controller click each start their matching handler. The Gate responds to refresh. Order within an individual stack matters, but moving separate stacks vertically does not establish a reliable global running order. Both action handlers call one named custom block so the same count-update logic is maintained in one place. Block-based code still requires precise rules and tests.
  2. The Controller changes one count variable created for all sprites. The Gate reads that same value after receiving refresh. The broadcast name is a trigger and does not automatically transport a numerical payload. Two sprite-only variables with the same name can be distinct. Reset sets count to zero before broadcasting; the action procedure changes count by one before broadcasting.
  3. Scratch uses a count-greater-than-two block; the Python model uses count at least three. They agree for the stipulated non-negative integer action counts. A decimal two and a half shows why this is not a universal equivalence over all numbers. The Python contract explicitly rejects non-integer, Boolean and negative counts. The scene is a fictional counter, not an official learning score.
  4. For flag,click,space,click,other,flag,space, the successive counts are zero,one,two,three,three,zero,one. Gate text becomes Gate open at the first three and remains so through the ignored event, then returns to Keep exploring after reset and at the final one. Reset must update the visible receiver as well as the stored variable. Each event is completed before the next in this stated trace.
  5. Broadcast and wait holds its sender until the receiving scripts triggered by that message finish; it does not freeze the whole project or impose an order between independent receivers. The supplied Python functions process explicit event values and return model state. They do not render sprites, install key listeners or execute Scratch. The comparison was actually tested as Python; a learner must separately build and test the Scratch project to claim that practical evidence.
  6. If count changes without new Gate text, inspect the receiver, message spelling and variable scope. If one action adds twice, inspect duplicate handlers. Keep a visible tappable control, keyboard route and textual feedback for different users. A timed or overlapping-input extension needs explicit coordination and new tests. Preserve original work, use fictional data and label paper reasoning, Python runs and actual Scratch execution separately.


Learning evidence

Submit the original saved project if built, both sprite-script views, the exact trace and actual tests of reset, keyboard input, click/tap input and boundary three. Include an anonymous usability requirement and a justified revision. Clearly label paper predictions, executed Python logic comparisons and separately executed Scratch tests; do not substitute a screenshot of an unrelated editor project for build evidence.


OER and Wikipedia

Original Controller/Gate specification, block inventories, trace, Python comparison, test expectations and assessments. Scratch Team: broadcast and broadcast and wait provide primary semantics; the official help index and current Scratch Foundation Learning Library support project development. Python Software Foundation control flow supports the separate original textual model. DfE Computing programme of study, KS3 multi-language programming and creative projects: Year 7 allocation is editorial, and this single scene does not prove the entire stage programme. Primary sources checked 13 November 2026. Videos use the original Scratch Team publications. Commons imagery is contextual and unchanged; no unrelated photographed program is presented as the original project.

Scratch 3.0 editor.png, Screenshot is own work, Scratch is by MIT and other contributors, CC BY-SA 2.0. Unchanged original; caption and learning activities are original.

Toy Blocks (50995087111).jpg, ajay_suresh, CC BY 2.0. Unchanged original; caption and learning activities are original.

Python Code.jpg, Weal2019, CC0. Unchanged original; caption and learning activities are original.


Linked learning areas


aiMOOC Projects



Schulfach+




aiMOOCs



aiMOOC Projekte









MOOCwiki · Deutsch

Nach dem Lernen ist vor dem Lernen

Entdecke direkt den nächsten Lernkurs. Weitere Inhalte erscheinen, wenn Du weiter nach unten scrollst.

Zur MOOCwiki-Hauptseite

Mediathek

Suche verfeinern

Dein Lernplan bestimmt, was oben steht. Alle anderen Inhalte bleiben erreichbar. Seitenaufrufe beeinflussen die Auswahl nicht.

Inhalte werden geladen ...

Mediathek wird aus dem Wiki geladen ...