ICSOC-8.11.3 Event Handling and Program Triggers (M)

Easy

ICSOC-8.11.3.1 The Green Flag Trigger: Asynchronous Startup, Thread Initialization, and Global State Reset

The Green Flag Trigger: Asynchronous Startup, Thread Initialization, and Global State Reset

In event-driven visual programming environments like Scratch 3.0, execution does not begin from a static textual main() routine; instead, it is coordinated through specialized event-listening triggers known as “hat blocks.” Distinctively contoured with a curved top and a bottom connection notch, hat blocks can only sit at the head of a script stack and cannot be nested underneath other blocks. The “when green flag clicked” hat block serves as the universal runtime initialization event for an entire project. When a user clicks the green flag icon above the Stage canvas, the Scratch runtime dispatcher broadcasts a global start signal, activating all threads crowned with this trigger concurrently across every sprite and the backdrop.

Because multiple scripts throughout the project can listen for the exact same green flag event, execution proceeds in parallel under cooperative multi-threading managed by the virtual machine’s event loop. This simultaneous launch introduces classic race conditions if different scripts attempt to read or mutate identical shared variables or stage positions during the first execution frame. To establish deterministic initialization, robust Olympiad-level Scratch architectures designate a single master setup script that clears stage graphic effects, resets variable states, and sets coordinate baselines before triggering subsequent gameplay sequences via broadcast messages.

Easy
What is the primary functional characteristic of a “hat block” (such as [when green flag clicked]) in Scratch 3.0?
Option A is correct because hat blocks are characterized by their rounded top edge and bottom connection notch, designed specifically to serve as event listeners that initiate script stacks when triggered. Option B is incorrect because hat blocks cannot connect underneath other blocks and cannot be nested within control structures. Option C is incorrect because reporter and boolean blocks handle arithmetic and data evaluation, not hat blocks. Option D is incorrect because the [stop all] block halts threads, whereas hat blocks start them.
Medium
A project contains two separate scripts under [when green flag clicked] in the same sprite. Script 1 sets a variable [Score] to 10, while Script 2 changes [Score] by 5. What software concurrency challenge does this scenario illustrate?
Option A is correct because when multiple scripts share the same startup trigger and access the same shared state without explicit sequencing, a race condition occurs. Depending on thread interleaving, Script 2 could read [Score] before or after Script 1 initializes it. Option B is incorrect because Scratch is an interpreted environment that dynamically schedules concurrent threads without throwing compile syntax errors. Option C is incorrect because neither script contains blocking locks that would cause deadlock. Option D is incorrect because modifying a numeric variable updates its value in-place without leaking memory.
Tricky
A Scratch programmer wants to guarantee that global variable initialization across 10 sprites completes entirely before any character movement scripts begin executing. What is the most architecturally robust solution?
Option A is correct because the [broadcast [message] and wait] block pauses the master coordinator script until all receiving event handlers across all sprites finish executing their initialization routines, enforcing deterministic synchronization. Option B is incorrect because arbitrary time delays are brittle heuristics that fail under varying hardware performance or high frame loads. Option C is incorrect because creating redundant identical hat triggers compounds race conditions rather than resolving them. Option D is incorrect because sprite execution priority is governed by dynamic internal Z-order and display lists, not alphabetical naming conventions.
Medium

ICSOC-8.11.3.2 Keyboard Event Triggers: Hardware Polling vs. Operating System Event Buffers

Keyboard Event Triggers: Hardware Polling vs. Operating System Event Buffers

Scratch provides two fundamentally distinct architectural mechanisms for responding to user keyboard inputs: discrete interrupt-style event handling via the “when [key v] pressed” hat block, and continuous state querying via the boolean sensing reporter block ““. The “when [key v] pressed” hat block binds an execution stack directly to the operating system’s keyboard event listener. When a designated key is actuated, the event dispatcher captures the key-down event and fires the corresponding script once. However, because this trigger relies on standard OS keyboard repeat delay and typematic repeat rates, holding a key down causes a noticeable pause between the initial actuation and repetitive firing, making discrete hat blocks suboptimal for fluid, continuous game character locomotion.

For precision real-time player controls, game developers avoid hat-based keyboard triggers and instead embed “” boolean sensing blocks within an unbounded “forever” polling loop synchronized to the runtime’s 30 frames-per-second (FPS) display refresh rate. While the event hat block operates asynchronously outside the main game loop, polling provides instantaneous, deterministic per-tick evaluation of multi-key inputs (such as diagonal movement via simultaneous up-arrow and right-arrow actuation). Understanding this architectural dichotomy between event-driven key interrupts and frame-synchronous boolean polling is essential for diagnosing input lag and designing competitive arcade mechanics.

Easy
Which block category contains the [when [space v] key pressed] event listener block in Scratch 3.0?
Option A is correct because all discrete event-triggering hat blocks, including [when [key] pressed], belong to the Events category (colored yellow). Option B is incorrect because Sensing blocks include the boolean reporter [], not the hat trigger. Option C is incorrect because Control blocks manage loops and branching logic. Option D is incorrect because Operators perform mathematical, logical, and string manipulations.
Medium
Why does using [when [right arrow v] key pressed: change x by 10] cause choppy, stuttering movement when a player holds down the arrow key in a game?
Option A is correct because the [when [key] pressed] hat block binds to OS-level keypress events. When a key is held down, the OS registers a single keydown, pauses for a user-configured typematic delay (typically 250-500ms), and only then emits rapid repeat events. Option B is incorrect because Scratch motion steps are governed by block parameters, not arbitrary 1 step/second caps. Option C is incorrect because block interpretation occurs at microsecond speeds. Option D is incorrect because keys can fire repeatedly after the initial OS repeat delay.
Tricky
To achieve smooth, 30 FPS responsive diagonal player locomotion (moving simultaneously along both X and Y axes), how should the input scripts be structured?
Option A is correct because polling discrete boolean reporters within a continuous frame-synchronized game loop checks both keys independently during every 30 FPS render tick, allowing both X and Y displacements to execute in the same frame for seamless diagonal translation. Option B is incorrect because discrete hat triggers suffer from OS typematic repeat delays and cannot cleanly synchronize simultaneous keypresses. Option C is incorrect because nesting within an else-branch makes the two directions mutually exclusive, preventing simultaneous diagonal movement. Option D is incorrect because [wait until] halts thread execution until a single key is actuated and cannot track continuous multi-axis coordinates.
Easy

ICSOC-8.11.3.3 Mouse Interactivity: Hit Testing, Transparency Masking, and Sprite Layering

Mouse Interactivity: Hit Testing, Transparency Masking, and Sprite Layering

The “when this sprite clicked” hat block transforms any visual actor into an interactive graphical user interface (GUI) control, such as a clickable button, collectible item, or dialog choice. When a primary pointer down event occurs, the Scratch rendering engine executes a real-time point-in-polygon spatial hit test against the bounding geometry of visible sprites. Notably, Scratch evaluates clicks against the exact non-transparent pixel boundary of the sprite’s current costume texture rather than its outer rectangular bounding box. Furthermore, a sprite whose visual opacity has been set to 100 via the “ghost” graphic effect remains completely responsive to mouse-click triggers because its collision geometry is preserved in the rendering buffer, whereas a sprite hidden via the “hide” block is deactivated from the hit-testing pipeline and will not trigger click events.

Layer hierarchy (Z-ordering) also dictates mouse event handling when multiple sprites overlap on the Stage canvas. When two clickable sprites occupy the same Cartesian coordinates, the mouse-click event is intercepted exclusively by the sprite residing at the highest visual layer. The occluded sprite situated underneath does not receive the click event unless the top sprite is explicitly hidden or lacks an event listener. This occlusion model allows programmers to construct layered modal dialogues and nested interface menus that naturally intercept pointer interactions while shielding background gameplay elements from unintended activation.

Easy
When the user clicks the primary mouse button on the Stage canvas, which entity receives the [when this sprite clicked] event?
Option A is correct because the [when this sprite clicked] hat block triggers only on the specific sprite whose visual costume geometry intersects the mouse cursor coordinates during a click event. Option B is incorrect because clicks are localized point-in-polygon events, not global broadcasts. Option C is incorrect because the Stage has its own separate [when stage clicked] hat block and does not intercept clicks meant for overlying sprites. Option D is incorrect because click detection functions across the entire (-240 to +240, -180 to +180) Stage canvas.
Medium
Sprite 1 and Sprite 2 are completely overlapping at coordinate (0, 0). Sprite 1 is at the front layer, and Sprite 2 is at the back layer. Both sprites have identical [when this sprite clicked: change [Score] by 1] scripts. If the user clicks on the overlapping region, what happens to [Score]?
Option A is correct because Scratch hit-testing is occlusion-sensitive: the mouse click event is captured exclusively by the topmost sprite in the Z-ordering visual stack. The underlying Sprite 2 is occluded and does not receive the click event. Option B is incorrect because click events in Scratch do not propagate through overlapping sprites. Option C is incorrect because overlapping sprites do not disable hit detection. Option D is incorrect because hit-testing is deterministic and strictly adheres to layer hierarchy, not random selection.
Tricky
A developer wants a sprite to be visually invisible to the player but still remain capable of being clicked to reveal an Easter egg. How should the sprite’s visibility be configured?
Option A is correct because setting the ghost effect to 100 renders the sprite 100% transparent while keeping it active in the rendering and hit-testing pipeline, allowing it to register mouse clicks and collisions. Option B is incorrect because [hide] completely removes the sprite from the active display list and disables all mouse-click hit detection. Option C is incorrect because Scratch clamps sprite minimum size, and a 0-size hitbox would offer no clickable area. Option D is incorrect because Scratch hit-testing checks non-transparent costume pixels; a costume containing zero non-transparent pixels cannot be clicked.
Medium

ICSOC-8.11.3.4 Stage Scene Coordination: Backdrop Change Triggers and State Machine Transitions

Stage Scene Coordination: Backdrop Change Triggers and State Machine Transitions

In modular software engineering, finite state machines (FSMs) organize complex application workflows into distinct operational states—such as Title Screen, Level Gameplay, Game Over, and Victory screens. In Scratch 3.0, the “when backdrop switches to [backdrop v]” hat block provides a native, stage-driven architectural trigger for managing global state transitions. When the Stage or any executing sprite issues a “switch backdrop to [backdrop v]” command, the runtime environment immediately broadcasts an internal notification across all project entities. Any script anchored by a matching backdrop trigger awakens instantaneously, enabling distributed sprites to dynamically spawn, reposition, adjust visual visibility, or purge obsolete local state variables in lockstep with scene progression.

Backdrop switch triggers offer structural advantages over generic broadcast messages by coupling visual environment rendering directly to programmatic lifecycle control. When transitioning scenes, a single backdrop switch simultaneously updates the visual Stage aesthetic and triggers corresponding stage-specific scripts across dozens of independent sprites, reducing code clutter and message overhead. Furthermore, unlike green-flag startup triggers that fire only once during project initialization, backdrop event handlers can be reinvoked cyclically whenever levels reset or menu loops reoccur, establishing a clean, deterministic architecture for multi-level games and interactive digital simulations.

Easy
Which block enables a sprite to automatically execute a script whenever the game scene transitions from the title menu to “Level 1”?
Option A is correct because [when backdrop switches to [backdrop]] is the specialized hat block that listens for scene changes initiated by the Stage or sprites, triggering immediately when the designated backdrop becomes active. Option B is incorrect because it requires a user mouse click. Option C is incorrect because it responds to elapsed time. Option D is incorrect because it responds to microphone volume.
Medium
What primary architectural advantage does using [when backdrop switches to [backdrop v]] offer over multiple separate [broadcast [message v]] blocks for level management?
Option A is correct because changing the backdrop both visually renders the new scene and simultaneously fires event handlers across all listening sprites, ensuring cohesive synchronization without requiring a supplementary [broadcast] block for every scene change. Option B is incorrect because all Scratch event triggers operate within the same virtual machine event loop without hardware-level priority overrides. Option C is incorrect because all executing threads require memory allocations for local contexts. Option D is incorrect because backdrop switches do not alter variable values unless explicit code instructions do so.
Tricky
A Scratch project currently displaying backdrop “GameOver” executes the block [switch backdrop to [GameOver v]]. What happens to the scripts crowned with [when backdrop switches to [GameOver v]]?
Option A is correct because in Scratch 3.0, issuing a [switch backdrop to [backdrop]] command always emits the corresponding backdrop switch event even if the specified backdrop is already active. Any script attached to that backdrop hat block will re-trigger from the top, resetting its thread execution. Option B is incorrect because Scratch does not deduplicate or suppress identical backdrop switch calls. Option C is incorrect because re-triggering simply restarts the attached thread rather than causing a stack overflow crash. Option D is incorrect because switching to the same backdrop does not clear costumes or corrupt the canvas.
Tricky

ICSOC-8.11.3.5 Sensor Triggers: Continuous Edge Detection, Threshold Comparators, and Runtime Watchdogs

Sensor Triggers: Continuous Edge Detection, Threshold Comparators, and Runtime Watchdogs

Scratch provides a specialized autonomous monitoring hat block: the “when [loudness | timer v] > (value)” threshold trigger. Unlike standard event hats that react to discrete user actions or system messages, the sensor hat block functions as an edge-triggered runtime comparator. The Scratch execution engine continuously interrogates the designated internal sensor value (such as the elapsed project execution time tracked by the built-in system “timer” or real-time audio amplitude sampled via the microphone “loudness” sensor from 0 to 100) at each engine step cycle, evaluating the boolean predicate SensorValue > Threshold.

A vital architectural nuance of this block lies in its edge-triggered firing condition. The script attached to “when [timer] > (5)” triggers precisely at the moment the continuous variable transitions from less-than-or-equal-to 5 into greater-than 5. While the condition remains true indefinitely thereafter, the runtime engine does not continuously re-fire the hat block on every frame. For the trigger to fire a second time, the monitored value must first drop back to or below the threshold and subsequently cross above it once again (e.g., if the timer is reset to zero via the “reset timer” block). This edge-triggered state latching prevents infinite thread recursion, making sensor hat blocks ideal for asynchronous timeouts, countdown game-over sequences, and acoustic amplitude triggers.

Easy
Which internal sensor values can be monitored directly using the [when [sensor v] > (value)] hat block in Scratch 3.0?
Option A is correct because the built-in [when [ v] > ( )] hat block dropdown specifically provides options for “loudness” (microphone volume from 0 to 100) and “timer” (project elapsed seconds). Option B is incorrect because mouse coordinates are queried using Sensing reporter blocks, not this hat block’s dropdown. Option C is incorrect because costume number and size are Looks properties. Option D is incorrect because sound volume and pitch are Sound attributes.
Medium
A script begins with [when [timer v] > 10: say [Time’s Up!] for 2 seconds]. The timer starts at 0 and increments continuously to 15 without being reset. How many times will the script execute?
Option A is correct because the sensor hat block is edge-triggered. It fires exclusively upon the rising edge transition where the condition evaluates from false (<= 10) to true (> 10). Once the threshold is crossed, the script will not re-trigger while the condition remains continuously true. Option B is incorrect because level-triggered continuous firing would cause infinite restarts. Option C is incorrect because the trigger specifies a threshold of 10, not an interval timer. Option D is incorrect because sensor hat blocks execute autonomously without requiring mouse clicks.
Tricky
A programmer builds a noise-activated jump mechanic using [when [loudness v] > 30: change y by 50; wait 0.5 seconds; change y by -50]. If a player continuously shouts into the microphone for 5 seconds at a steady loudness of 60, what occurs?
Option A is correct because the [when [loudness] > 30] hat block triggers only on the rising edge transition from <= 30 to > 30. During the continuous 5-second shout, the condition remains persistently true, so no new rising edge occurs. The sprite completes its single jump up and down, and will not jump again until the ambient volume falls to 30 or below before rising above 30 once more. Option B is incorrect because the block does not re-trigger while the threshold remains continuously satisfied. Option C is incorrect because audio sampling does not cause buffer overflows. Option D is incorrect because Scratch does not dynamically alter user-defined block parameters.