scratch_agent / utils /script_plan.py
WebashalarForML's picture
Upload 24 files
3d3703f verified
import json
import copy
import re
def generate_blocks_from_opcodes(opcode_counts, all_block_definitions):
"""
Generates a dictionary of Scratch-like blocks based on a list of opcodes and a reference block definition.
It now correctly links parent and menu blocks using their generated unique keys, and handles various block categories.
It ensures that menu blocks are only generated as children of their respective parent blocks.
Args:
opcode_counts (list): An array of objects, each with an 'opcode' and 'count' property.
Example: [{"opcode": "motion_gotoxy", "count": 1}]
all_block_definitions (dict): A comprehensive dictionary containing definitions for all block types.
Returns:
tuple: A tuple containing:
- dict: A JSON object where keys are generated block IDs and values are the block definitions.
- dict: The opcode_occurrences dictionary for consistent unique key generation across functions.
"""
generated_blocks = {}
opcode_occurrences = {} # To keep track of how many times each opcode (main or menu) has been used for unique keys
# Define explicit parent-menu relationships for linking purposes
# This maps main_opcode -> list of (input_field_name, menu_opcode)
explicit_menu_links = {
"motion_goto": [("TO", "motion_goto_menu")],
"motion_glideto": [("TO", "motion_glideto_menu")],
"motion_pointtowards": [("TOWARDS", "motion_pointtowards_menu")],
"sensing_keypressed": [("KEY_OPTION", "sensing_keyoptions")],
"sensing_of": [("OBJECT", "sensing_of_object_menu")],
"sensing_touchingobject": [("TOUCHINGOBJECTMENU", "sensing_touchingobjectmenu")],
"control_create_clone_of": [("CLONE_OPTION", "control_create_clone_of_menu")],
"sound_play": [("SOUND_MENU", "sound_sounds_menu")],
"sound_playuntildone": [("SOUND_MENU", "sound_sounds_menu")],
"looks_switchcostumeto": [("COSTUME", "looks_costume")],
"looks_switchbackdropto": [("BACKDROP", "looks_backdrops")],
}
# --- Step 1: Process explicitly requested opcodes and generate their instances and associated menus ---
for item in opcode_counts:
opcode = item.get("opcode")
count = item.get("count", 1)
# Special handling for 'sensing_istouching' which maps to 'sensing_touchingobject'
if opcode == "sensing_istouching":
opcode = "sensing_touchingobject"
if not opcode:
print("Warning: Skipping item with missing 'opcode'.")
continue
if opcode not in all_block_definitions:
print(f"Warning: Opcode '{opcode}' not found in all_block_definitions. Skipping.")
continue
for _ in range(count):
# Increment occurrence count for the current main opcode
opcode_occurrences[opcode] = opcode_occurrences.get(opcode, 0) + 1
main_block_instance_num = opcode_occurrences[opcode]
main_block_unique_key = f"{opcode}_{main_block_instance_num}"
# Create a deep copy of the main block definition
main_block_data = copy.deepcopy(all_block_definitions[opcode])
# Set properties for a top-level main block
main_block_data["parent"] = None
main_block_data["next"] = None
main_block_data["topLevel"] = True
main_block_data["shadow"] = False # Main blocks are typically not shadows
generated_blocks[main_block_unique_key] = main_block_data
# If this main block has associated menus, generate and link them now
if opcode in explicit_menu_links:
for input_field_name, menu_opcode_type in explicit_menu_links[opcode]:
if menu_opcode_type in all_block_definitions:
# Increment the occurrence for the menu block type
opcode_occurrences[menu_opcode_type] = opcode_occurrences.get(menu_opcode_type, 0) + 1
menu_block_instance_num = opcode_occurrences[menu_opcode_type]
menu_block_data = copy.deepcopy(all_block_definitions[menu_opcode_type])
# Generate a unique key for this specific menu instance
menu_unique_key = f"{menu_opcode_type}_{menu_block_instance_num}"
# Set properties for a shadow menu block
menu_block_data["shadow"] = True
menu_block_data["topLevel"] = False
menu_block_data["next"] = None
menu_block_data["parent"] = main_block_unique_key # Link menu to its parent instance
# Update the main block's input to point to this unique menu instance
if input_field_name in main_block_data.get("inputs", {}) and \
isinstance(main_block_data["inputs"][input_field_name], list) and \
len(main_block_data["inputs"][input_field_name]) > 1 and \
main_block_data["inputs"][input_field_name][0] == 1:
main_block_data["inputs"][input_field_name][1] = menu_unique_key
generated_blocks[menu_unique_key] = menu_block_data
return generated_blocks, opcode_occurrences
def interpret_pseudo_code_and_update_blocks(generated_blocks_json, pseudo_code, all_block_definitions, opcode_occurrences):
"""
Interprets pseudo-code to update the generated Scratch blocks, replacing static values
with dynamic values and establishing stacking/nesting logic.
Args:
generated_blocks_json (dict): The JSON object of pre-generated blocks.
pseudo_code (str): The pseudo-code string to interpret.
all_block_definitions (dict): A comprehensive dictionary containing definitions for all block types.
opcode_occurrences (dict): A dictionary to keep track of opcode occurrences for unique key generation.
Returns:
dict: The updated JSON object of Scratch blocks.
"""
updated_blocks = copy.deepcopy(generated_blocks_json)
# Helper to create a new block instance (used for shadows/nested blocks)
def create_block_instance_for_parsing(opcode, parent_key=None, is_shadow=False, is_top_level=False):
opcode_occurrences[opcode] = opcode_occurrences.get(opcode, 0) + 1
unique_key = f"{opcode}_{opcode_occurrences[opcode]}"
new_block = copy.deepcopy(all_block_definitions.get(opcode, {}))
if not new_block:
print(f"Error: Definition for opcode '{opcode}' not found when creating instance for parsing.")
return None, None
new_block["parent"] = parent_key
new_block["next"] = None
new_block["topLevel"] = is_top_level
new_block["shadow"] = is_shadow
# Initialize inputs/fields to default empty values, but preserve structure
if "inputs" in new_block:
for input_name, input_data in new_block["inputs"].items():
if isinstance(input_data, list) and len(input_data) > 1:
if input_data[0] == 1: # Block reference
new_block["inputs"][input_name][1] = None # Placeholder for linked block ID
elif input_data[0] in [4, 5, 6, 7, 8, 9, 10]: # Literal types
new_block["inputs"][input_name][1] = "" # Default empty literal
if "fields" in new_block:
for field_name, field_data in new_block["fields"].items():
if isinstance(field_data, list) and len(field_data) > 0:
new_block["fields"][field_name][0] = "" # Default empty field value
updated_blocks[unique_key] = new_block
return unique_key, new_block
# Helper to parse input values from pseudo-code and create nested blocks if necessary
def parse_and_link_input(parent_block_key, input_type, pseudo_value, input_name_in_parent=None, field_name_in_parent=None):
pseudo_value = pseudo_value.strip()
# 1. Handle literal numbers (e.g., "2", "+1", "-135")
if re.fullmatch(r"[-+]?\d+(\.\d+)?", pseudo_value):
return [4, pseudo_value] # Type 4 for number literal
# 2. Handle literal strings (e.g., "Game Over") - often in quotes or simply text
# If it's a broadcast message, it's typically a string literal.
# If it's a 'say' message, it's a string literal.
# If it's a variable name, it's handled by specific patterns later.
if pseudo_value.startswith('"') and pseudo_value.endswith('"'):
return [10, pseudo_value.strip('"')] # Type 10 for string literal
# 3. Handle variable names (e.g., "[score v]", "[Sprite1 v]", "[Game Over v]")
# These can be fields or inputs that expect a variable reporter block.
var_match = re.match(r"\[(.+?) v\]", pseudo_value)
if var_match:
var_name = var_match.group(1).strip()
# If it's a field (like for set variable, show variable)
if field_name_in_parent:
return var_name # Return name, parent block will set its field
# If it's an input that expects a variable reporter (e.g., 'say (score)')
# Create a data_variable shadow block
var_reporter_key, var_reporter_data = create_block_instance_for_parsing(
"data_variable", parent_key=parent_block_key, is_shadow=True
)
if var_reporter_key:
var_reporter_data["fields"]["VARIABLE"] = [var_name, f"`var_{var_name}"] # Placeholder ID
return [1, var_reporter_key] # Type 1 for block reference
else:
print(f"Warning: Could not create data_variable block for '{var_name}'")
return [10, var_name] # Fallback to string literal
# 4. Handle nested reporter blocks (e.g., "(x position)")
reporter_match = re.match(r"\((.+?)\)", pseudo_value)
if reporter_match:
inner_content = reporter_match.group(1).strip()
# Check if it's a known reporter block (like "x position")
if inner_content in reporter_opcode_lookup:
reporter_opcode = reporter_opcode_lookup[inner_content]
reporter_block_key, reporter_block_data = create_block_instance_for_parsing(
reporter_opcode, parent_key=parent_block_key, is_shadow=True
)
if reporter_block_key:
return [1, reporter_block_key] # Type 1 for block reference
else:
print(f"Warning: Could not create reporter block for '{inner_content}'")
return [10, inner_content] # Fallback to string literal
else: # It's a literal number or string inside parentheses
return parse_and_link_input(parent_block_key, input_type, inner_content) # Recurse for inner content
# 5. Handle nested boolean blocks (e.g., "<(...) < (...)>")
boolean_match = re.match(r"<(.+?)>", pseudo_value)
if boolean_match:
inner_condition_str = boolean_match.group(1).strip()
# This is typically handled by the parent block's parsing (e.g., control_if)
# For now, if called directly, it implies a boolean reporter.
# We'll need specific logic for operator_lt, operator_and, etc.
# This part is complex and often handled by the parent block's specific regex.
# For this problem, the 'if' block's logic will create the boolean shadow.
print(f"Warning: Direct parsing of standalone boolean '{pseudo_value}' not fully supported here.")
return [10, pseudo_value] # Fallback to string literal
# Default to string literal if no other pattern matches
return [10, pseudo_value]
lines = [line.strip() for line in pseudo_code.strip().split('\n') if line.strip()]
# Track the current script and nesting
current_script_head = None
block_stack = [] # Stores (parent_block_key, indent_level, last_child_key_in_scope)
# Create a mapping from block name patterns to their opcodes and input/field details
# The 'input_map' keys are the internal Scratch input names, values are regex group indices.
# The 'field_map' keys are the internal Scratch field names, values are regex group indices.
# 'condition_opcode' is for 'if' blocks that take a specific boolean reporter.
pseudo_code_to_opcode_map = {
re.compile(r"when green flag clicked"): {"opcode": "event_whenflagclicked"},
re.compile(r"go to x: \((.+?)\) y: \((.+?)\)"): {"opcode": "motion_gotoxy", "input_map": {"X": 0, "Y": 1}},
re.compile(r"set \[(.+?) v\] to (.+)"): {"opcode": "data_setvariableto", "field_map": {"VARIABLE": 0}, "input_map": {"VALUE": 1}},
re.compile(r"show variable \[(.+?) v\]"): {"opcode": "data_showvariable", "field_map": {"VARIABLE": 0}},
re.compile(r"forever"): {"opcode": "control_forever"},
re.compile(r"glide \((.+?)\) seconds to x: \((.+?)\) y: \((.+?)\)"): {"opcode": "motion_glidesecstoxy", "input_map": {"SECS": 0, "X": 1, "Y": 2}},
re.compile(r"if <\((.+)\) < \((.+)\)> then"): {"opcode": "control_if", "condition_type": "operator_lt", "condition_input_map": {"OPERAND1": 0, "OPERAND2": 1}},
re.compile(r"set x to \((.+?)\)"): {"opcode": "motion_setx", "input_map": {"X": 0}},
re.compile(r"if <touching \[(.+?) v\]\?> then"): {"opcode": "control_if", "condition_type": "sensing_touchingobject", "condition_field_map": {"TOUCHINGOBJECTMENU": 0}},
re.compile(r"broadcast \[(.+?) v\]"): {"opcode": "event_broadcast", "input_map": {"BROADCAST_INPUT": 0}},
re.compile(r"stop \[(.+?) v\]"): {"opcode": "control_stop", "field_map": {"STOP_OPTION": 0}},
re.compile(r"end"): {"opcode": "end_block"}, # Special marker for script end/C-block end
}
# Create a reverse lookup for reporter block opcodes based on their pseudo-code representation
reporter_opcode_lookup = {}
for opcode, definition in all_block_definitions.items():
if definition.get("block_shape") == "Reporter Block":
block_name = definition.get("block_name")
if block_name:
# Clean up block name for matching: remove parentheses, 'v' for variable, etc.
clean_name = block_name.replace("(", "").replace(")", "").replace("[", "").replace("]", "").replace(" v", "").strip()
reporter_opcode_lookup[clean_name] = opcode
# Add specific entries for common reporters if their pseudo-code differs from clean_name
if opcode == "motion_xposition":
reporter_opcode_lookup["x position"] = opcode
elif opcode == "motion_yposition":
reporter_opcode_lookup["y position"] = opcode
# Add more as needed based on pseudo-code patterns
for line_idx, raw_line in enumerate(lines):
current_line_indent = len(raw_line) - len(raw_line.lstrip())
line = raw_line.strip()
# Adjust block_stack based on current indent level
while block_stack and current_line_indent <= block_stack[-1][1]:
block_stack.pop()
matched_block_info = None
matched_values = None
# Try to match the line against known block patterns
for pattern_regex, info in pseudo_code_to_opcode_map.items():
match = pattern_regex.match(line)
if match:
matched_block_info = info
matched_values = match.groups()
break
if not matched_block_info:
print(f"Warning: Could not interpret line: '{line}' at line {line_idx + 1}")
continue
opcode = matched_block_info["opcode"]
# Handle 'end' block separately as it signifies closing a C-block
if opcode == "end_block":
# This 'end' matches the most recent C-block on the stack.
# The while loop at the beginning of the iteration already handles popping.
continue
parent_key = None
if block_stack:
parent_key = block_stack[-1][0] # The last block on the stack is the parent
# Create the new block instance
new_block_key, new_block_data = create_block_instance_for_parsing(
opcode,
parent_key=parent_key,
is_top_level=(parent_key is None)
)
if not new_block_key:
continue
# Link to previous block in the same script/nesting level
if block_stack:
# Update the 'next' of the previous block in the current scope
last_child_key_in_scope = block_stack[-1][2] if len(block_stack[-1]) > 2 else None
if last_child_key_in_scope and last_child_key_in_scope in updated_blocks:
updated_blocks[last_child_key_in_scope]["next"] = new_block_key
# Update the last child in the current scope
block_stack[-1] = (block_stack[-1][0], block_stack[-1][1], new_block_key)
# Populate inputs and fields based on matched_block_info and matched_values
if matched_values:
# Handle fields
if "field_map" in matched_block_info:
for field_name, group_idx in matched_block_info["field_map"].items():
pseudo_field_value = matched_values[group_idx].replace(' v', '').strip()
if field_name == "VARIABLE":
# For variable fields, the actual variable ID is often derived or generated.
# For now, we use a placeholder and the name.
new_block_data["fields"][field_name] = [pseudo_field_value, f"`var_{pseudo_field_value}"]
elif field_name == "STOP_OPTION":
new_block_data["fields"][field_name] = [pseudo_field_value, None] # No ID needed for dropdown option
else:
new_block_data["fields"][field_name][0] = pseudo_field_value
# Handle inputs
if "input_map" in matched_block_info:
for input_name, group_idx in matched_block_info["input_map"].items():
pseudo_input_value = matched_values[group_idx].strip()
parsed_input_info = parse_and_link_input(new_block_key, new_block_data["inputs"][input_name][0], pseudo_input_value, input_name_in_parent=input_name)
if parsed_input_info:
if parsed_input_info[0] == 1: # It's a linked block (shadow reporter/boolean/menu)
new_block_data["inputs"][input_name][1] = parsed_input_info[1] # Link block ID
new_block_data["inputs"][input_name][0] = parsed_input_info[0] # Set type to 1 (block)
else: # It's a literal value
new_block_data["inputs"][input_name][1] = parsed_input_info[1]
new_block_data["inputs"][input_name][0] = parsed_input_info[0] # Set appropriate type (4 for number, 10 for string)
# Special handling for 'if' block conditions
if opcode == "control_if":
condition_type = matched_block_info.get("condition_type")
if condition_type:
condition_block_key, condition_block_data = create_block_instance_for_parsing(
condition_type, parent_key=new_block_key, is_shadow=True
)
if condition_block_key:
new_block_data["inputs"]["CONDITION"] = [2, condition_block_key] # Type 2 for boolean block reference
# Populate inputs for the condition block (e.g., operator_lt)
if "condition_input_map" in matched_block_info:
for cond_input_name, cond_group_idx in matched_block_info["condition_input_map"].items():
pseudo_cond_value = matched_values[cond_group_idx].strip()
parsed_cond_input_info = parse_and_link_input(condition_block_key, condition_block_data["inputs"][cond_input_name][0], pseudo_cond_value)
if parsed_cond_input_info:
if parsed_cond_input_info[0] == 1:
condition_block_data["inputs"][cond_input_name][1] = parsed_cond_input_info[1]
condition_block_data["inputs"][cond_input_name][0] = parsed_cond_input_info[0]
else:
condition_block_data["inputs"][cond_input_name][1] = parsed_cond_input_info[1]
condition_block_data["inputs"][cond_input_name][0] = parsed_cond_input_info[0]
# Populate fields for the condition block (e.g., sensing_touchingobject's menu)
if "condition_field_map" in matched_block_info:
for cond_field_name, cond_group_idx in matched_block_info["condition_field_map"].items():
pseudo_cond_field_value = matched_values[cond_group_idx].replace(' v', '').strip()
if cond_field_name == "TOUCHINGOBJECTMENU":
# Create the menu block for TOUCHINGOBJECTMENU
menu_opcode = "sensing_touchingobjectmenu"
menu_key, menu_data = create_block_instance_for_parsing(
menu_opcode,
parent_key=condition_block_key,
is_shadow=True
)
if menu_key:
condition_block_data["inputs"]["TOUCHINGOBJECTMENU"] = [1, menu_key] # Link to menu block
menu_data["fields"]["TOUCHINGOBJECTMENU"] = [pseudo_cond_field_value, None] # Set menu value
else:
print(f"Warning: Could not create menu block for touching object: '{pseudo_cond_field_value}'")
else:
condition_block_data["fields"][cond_field_name][0] = pseudo_cond_field_value
else:
print(f"Warning: Could not create condition block '{condition_type}' for 'if' statement.")
# For C-blocks, push onto stack to track nesting
# 'control_if' is a C-block, but its 'next' is inside its substack.
# 'control_forever' is also a C-block.
if all_block_definitions[opcode].get("block_shape") == "C-Block" and opcode != "control_if":
# For C-blocks, the 'next' of the parent is usually null, and children start in 'SUBSTACK'
# We add the block to the stack, and its "next" will be its first child.
# The 'next' of the *last child* in its substack will point to the block after the C-block.
block_stack.append((new_block_key, current_line_indent, None)) # (parent_key, indent, last_child_key_in_substack)
# For C-blocks, the first child is linked via the 'SUBSTACK' input
new_block_data["inputs"]["SUBSTACK"] = [2, None] # Placeholder for the first child block ID
# For 'if' blocks, the 'next' of the parent is usually null, and children start in 'SUBSTACK'
if opcode == "control_if":
block_stack.append((new_block_key, current_line_indent, None))
new_block_data["inputs"]["SUBSTACK"] = [2, None] # Placeholder for the first child block ID
# Final pass to ensure topLevel is correctly set for the very first block of a script
for key, block in updated_blocks.items():
if block.get("parent") is None and block.get("next") is not None:
block["topLevel"] = True
elif block.get("parent") is None and block.get("next") is None and block.get("opcode") == "event_whenflagclicked":
block["topLevel"] = True # Ensure hat blocks are always topLevel
return updated_blocks
# --- Consolidated Block Definitions from all provided JSONs ---
# This dictionary should contain ALL block definitions from your JSON files.
# I'm using the provided definitions from the previous turn.
all_block_definitions = {
# motion_block.json
"motion_movesteps": {
"block_name": "move () steps", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_movesteps",
"functionality": "Moves the sprite forward by the specified number of steps in the direction it is currently facing. A positive value moves it forward, and a negative value moves it backward.",
"inputs": {"STEPS": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_turnright": {
"block_name": "turn right () degrees", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_turnright",
"functionality": "Turns the sprite clockwise by the specified number of degrees.",
"inputs": {"DEGREES": [1, [4, "15"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_turnleft": {
"block_name": "turn left () degrees", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_turnleft",
"functionality": "Turns the sprite counter-clockwise by the specified number of degrees.",
"inputs": {"DEGREES": [1, [4, "15"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_goto": {
"block_name": "go to ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_goto",
"functionality": "Moves the sprite to a specified location, which can be a random position or at the mouse pointer or another to the sprite.",
"inputs": {"TO": [1, "motion_goto_menu"]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_goto_menu": {
"block_name": "go to menu", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_goto_menu",
"functionality": "Menu for go to block.",
"inputs": {}, "fields": {"TO": ["_random_", None]}, "shadow": True, "topLevel": False
},
"motion_gotoxy": {
"block_name": "go to x: () y: ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_gotoxy",
"functionality": "Moves the sprite to the specified X and Y coordinates on the stage.",
"inputs": {"X": [1, [4, "0"]], "Y": [1, [4, "0"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_glideto": {
"block_name": "glide () secs to ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_glideto",
"functionality": "Glides the sprite smoothly to a specified location (random position, mouse pointer, or another sprite) over a given number of seconds.",
"inputs": {"SECS": [1, [4, "1"]], "TO": [1, "motion_glideto_menu"]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_glideto_menu": {
"block_name": "glide to menu", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_glideto_menu",
"functionality": "Menu for glide to block.",
"inputs": {}, "fields": {"TO": ["_random_", None]}, "shadow": True, "topLevel": False
},
"motion_glidesecstoxy": {
"block_name": "glide () secs to x: () y: ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_glidesecstoxy",
"functionality": "Glides the sprite smoothly to the specified X and Y coordinates over a given number of seconds.",
"inputs": {"SECS": [1, [4, "1"]], "X": [1, [4, "0"]], "Y": [1, [4, "0"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_pointindirection": {
"block_name": "point in direction ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_pointindirection",
"functionality": "Sets the sprite's direction to a specified angle in degrees (0 = up, 90 = right, 180 = down, -90 = left).",
"inputs": {"DIRECTION": [1, [8, "90"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_pointtowards": {
"block_name": "point towards ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_pointtowards",
"functionality": "Points the sprite towards the mouse pointer or another specified sprite.",
"inputs": {"TOWARDS": [1, "motion_pointtowards_menu"]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_pointtowards_menu": {
"block_name": "point towards menu", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_pointtowards_menu",
"functionality": "Menu for point towards block.",
"inputs": {}, "fields": {"TOWARDS": ["_mouse_", None]}, "shadow": True, "topLevel": False
},
"motion_changexby": {
"block_name": "change x by ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_changexby",
"functionality": "Changes the sprite's X-coordinate by the specified amount, moving it horizontally.",
"inputs": {"DX": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_setx": {
"block_name": "set x to ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_setx",
"functionality": "Sets the sprite's X-coordinate to a specific value, placing it at a precise horizontal position.",
"inputs": {"X": [1, [4, "0"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_changeyby": {
"block_name": "change y by ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_changeyby",
"functionality": "Changes the sprite's Y-coordinate by the specified amount, moving it vertically.",
"inputs": {"DY": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_sety": {
"block_name": "set y to ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_sety",
"functionality": "Sets the sprite's Y-coordinate to a specific value, placing it at a precise vertical position.",
"inputs": {"Y": [1, [4, "0"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_ifonedgebounce": {
"block_name": "if on edge, bounce", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_ifonedgebounce",
"functionality": "Reverses the sprite's direction if it touches the edge of the stage.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_setrotationstyle": {
"block_name": "set rotation style ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_setrotationstyle",
"functionality": "Determines how the sprite rotates: 'left-right' (flips horizontally), 'don't rotate' (stays facing one direction), or 'all around' (rotates freely).",
"inputs": {}, "fields": {"STYLE": ["left-right", None]}, "shadow": False, "topLevel": True
},
"motion_xposition": {
"block_name": "(x position)", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_xposition",
"functionality": "Reports the current X-coordinate of the sprite.[NOTE: not used in stage/backdrops]",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_yposition": {
"block_name": "(y position)", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_yposition",
"functionality": "Reports the current Y coordinate of the sprite on the stage.[NOTE: not used in stage/backdrops]",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"motion_direction": {
"block_name": "(direction)", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_direction",
"functionality": "Reports the current direction of the sprite in degrees (0 = up, 90 = right, 180 = down, -90 = left).[NOTE: not used in stage/backdrops]",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
# control_block.json
"control_wait": {
"block_name": "wait () seconds", "block_type": "Control", "block_shape": "Stack Block", "op_code": "control_wait",
"functionality": "Pauses the script for a specified duration.",
"inputs": {"DURATION": [1, [5, "1"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"control_repeat": {
"block_name": "repeat ()", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_repeat",
"functionality": "Repeats the blocks inside it a specified number of times.",
"inputs": {"TIMES": [1, [6, "10"]], "SUBSTACK": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
},
"control_forever": {
"block_name": "forever", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_forever",
"functionality": "Continuously runs the blocks inside it.",
"inputs": {"SUBSTACK": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
},
"control_if": {
"block_name": "if <> then", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_if",
"functionality": "Executes the blocks inside it only if the specified boolean condition is true. [NOTE: it takes boolean blocks as input]",
"inputs": {"CONDITION": [2, None], "SUBSTACK": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
},
"control_if_else": {
"block_name": "if <> then else", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_if_else",
"functionality": "Executes one set of blocks if the specified boolean condition is true, and a different set of blocks if the condition is false. [NOTE: it takes boolean blocks as input]",
"inputs": {"CONDITION": [2, None], "SUBSTACK": [2, None], "SUBSTACK2": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
},
"control_wait_until": {
"block_name": "wait until <>", "block_type": "Control", "block_shape": "Stack Block", "op_code": "control_wait_until",
"functionality": "Pauses the script until the specified boolean condition becomes true. [NOTE: it takes boolean blocks as input]",
"inputs": {"CONDITION": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
},
"control_repeat_until": {
"block_name": "repeat until <>", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_repeat_until",
"functionality": "Repeats the blocks inside it until the specified boolean condition becomes true. [NOTE: it takes boolean blocks as input]",
"inputs": {"CONDITION": [2, None], "SUBSTACK": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
},
"control_stop": {
"block_name": "stop [v]", "block_type": "Control", "block_shape": "Cap Block", "op_code": "control_stop",
"functionality": "Halts all scripts, only the current script, or other scripts within the same sprite. Its shape can dynamically change based on the selected option.",
"inputs": {}, "fields": {"STOP_OPTION": ["all", None]}, "shadow": False, "topLevel": True, "mutation": {"tagName": "mutation", "children": [], "hasnext": "false"}
},
"control_start_as_clone": {
"block_name": "When I Start as a Clone", "block_type": "Control", "block_shape": "Hat Block", "op_code": "control_start_as_clone",
"functionality": "This Hat block initiates the script when a clone of the sprite is created. It defines the behavior of individual clones.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"control_create_clone_of": {
"block_name": "create clone of ()", "block_type": "Control", "block_shape": "Stack Block", "op_code": "control_create_clone_of",
"functionality": "Generates a copy, or clone, of a specified sprite (or 'myself' for the current sprite).",
"inputs": {"CLONE_OPTION": [1, "control_create_clone_of_menu"]}, "fields": {}, "shadow": False, "topLevel": True
},
"control_create_clone_of_menu": {
"block_name": "create clone of menu", "block_type": "Control", "block_shape": "Reporter Block", "op_code": "control_create_clone_of_menu",
"functionality": "Menu for create clone of block.",
"inputs": {}, "fields": {"CLONE_OPTION": ["_myself_", None]}, "shadow": True, "topLevel": False
},
"control_delete_this_clone": {
"block_name": "delete this clone", "block_type": "Control", "block_shape": "Cap Block", "op_code": "control_delete_this_clone",
"functionality": "Removes the clone that is executing it from the stage.",
"inputs":None, "fields": {}, "shadow": False, "topLevel": True
},
# data_block.json
"data_setvariableto": {
"block_name": "set [my variable v] to ()", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_setvariableto",
"functionality": "Assigns a specific value (number, string, or boolean) to a variable.",
"inputs": {"VALUE": [1, [10, "0"]]}, "fields": {"VARIABLE": ["my variable", "`jEk@4|i[#Fk?(8x)AV.-my variable"]}, "shadow": False, "topLevel": True
},
"data_changevariableby": {
"block_name": "change [my variable v] by ()", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_changevariableby",
"functionality": "Increases or decreases a variable's numerical value by a specified amount.",
"inputs": {"VALUE": [1, [4, "1"]]}, "fields": {"VARIABLE": ["my variable", "`jEk@4|i[#Fk?(8x)AV.-my variable"]}, "shadow": False, "topLevel": True
},
"data_showvariable": {
"block_name": "show variable [my variable v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_showvariable",
"functionality": "Makes a variable's monitor visible on the stage.",
"inputs": {}, "fields": {"VARIABLE": ["my variable", "`jEk@4|i[#Fk?(8x)AV.-my variable"]}, "shadow": False, "topLevel": True
},
"data_hidevariable": {
"block_name": "hide variable [my variable v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_hidevariable",
"functionality": "Hides a variable's monitor from the stage.",
"inputs": {}, "fields": {"VARIABLE": ["my variable", "`jEk@4|i[#Fk?(8x)AV.-my variable"]}, "shadow": False, "topLevel": True
},
"data_addtolist": {
"block_name": "add () to [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_addtolist",
"functionality": "Appends an item to the end of a list.",
"inputs": {"ITEM": [1, [10, "thing"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_deleteoflist": {
"block_name": "delete () of [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_deleteoflist",
"functionality": "Removes an item from a list by its index or by selecting 'all' items.",
"inputs": {"INDEX": [1, [7, "1"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_deletealloflist": {
"block_name": "delete all of [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_deletealloflist",
"functionality": "Removes all items from a list.",
"inputs": {}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_insertatlist": {
"block_name": "insert () at () of [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_insertatlist",
"functionality": "Inserts an item at a specific position within a list.",
"inputs": {"ITEM": [1, [10, "thing"]], "INDEX": [1, [7, "1"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_replaceitemoflist": {
"block_name": "replace item () of [my list v] with ()", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_replaceitemoflist",
"functionality": "Replaces an item at a specific position in a list with a new value.",
"inputs": {"INDEX": [1, [7, "1"]], "ITEM": [1, [10, "thing"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_itemoflist": {
"block_name": "(item (2) of [myList v])", "block_type": "Data", "block_shape": "Reporter Block", "op_code": "data_itemoflist",
"functionality": "Reports the item located at a specific position in a list.",
"inputs": {"INDEX": [1, [7, "1"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_itemnumoflist": {
"block_name": "(item # of [Dog] in [myList v])", "block_type": "Data", "block_shape": "Reporter Block", "op_code": "data_itemnumoflist",
"functionality": "Reports the index number of the first occurrence of a specified item in a list. If the item is not found, it reports 0.",
"inputs": {"ITEM": [1, [10, "thing"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_lengthoflist": {
"block_name": "(length of [myList v])", "block_type": "Data", "block_shape": "Reporter Block", "op_code": "data_lengthoflist",
"functionality": "Provides the total number of items contained in a list.",
"inputs": {}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_listcontainsitem": {
"block_name": "<[my list v] contains ()?>", "block_type": "Data", "block_shape": "Boolean Block", "op_code": "data_listcontainsitem",
"functionality": "Checks if a list includes a specific item.",
"inputs": {"ITEM": [1, [10, "thing"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_showlist": {
"block_name": "show list [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_showlist",
"functionality": "Makes a list's monitor visible on the stage.",
"inputs": {}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_hidelist": {
"block_name": "hide list [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_hidelist",
"functionality": "Hides a list's monitor from the stage.",
"inputs": {}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
},
"data_variable": { # This is a reporter block for a variable's value
"block_name": "[variable v]", "block_type": "Data", "block_shape": "Reporter Block", "op_code": "data_variable",
"functionality": "Provides the current value stored in a variable.",
"inputs": {}, "fields": {"VARIABLE": ["my variable", None]}, "shadow": True, "topLevel": False
},
# event_block.json
"event_whenflagclicked": {
"block_name": "when green flag pressed", "block_type": "Events", "op_code": "event_whenflagclicked", "block_shape": "Hat Block",
"functionality": "This Hat block initiates the script when the green flag is clicked, serving as the common starting point for most Scratch projects.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"event_whenkeypressed": {
"block_name": "when () key pressed", "block_type": "Events", "op_code": "event_whenkeypressed", "block_shape": "Hat Block",
"functionality": "This Hat block initiates the script when a specified keyboard key is pressed.",
"inputs": {}, "fields": {"KEY_OPTION": ["space", None]}, "shadow": False, "topLevel": True
},
"event_whenthisspriteclicked": {
"block_name": "when this sprite clicked", "block_type": "Events", "op_code": "event_whenthisspriteclicked", "block_shape": "Hat Block",
"functionality": "This Hat block starts the script when the sprite itself is clicked.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"event_whenbackdropswitchesto": {
"block_name": "when backdrop switches to ()", "block_type": "Events", "op_code": "event_whenbackdropswitchesto", "block_shape": "Hat Block",
"functionality": "This Hat block triggers the script when the stage backdrop changes to a specified backdrop.",
"inputs": {}, "fields": {"BACKDROP": ["backdrop1", None]}, "shadow": False, "topLevel": True
},
"event_whengreaterthan": {
"block_name": "when () > ()", "block_type": "Events", "op_code": "event_whengreaterthan", "block_shape": "Hat Block",
"functionality": "This Hat block starts the script when a certain value (e.g., loudness from a microphone, or the timer) exceeds a defined threshold.",
"inputs": {"VALUE": [1, [4, "10"]]}, "fields": {"WHENGREATERTHANMENU": ["LOUDNESS", None]}, "shadow": False, "topLevel": True
},
"event_whenbroadcastreceived": {
"block_name": "when I receive ()", "block_type": "Events", "op_code": "event_whenbroadcastreceived", "block_shape": "Hat Block",
"functionality": "This Hat block initiates the script upon the reception of a specific broadcast message. This mechanism facilitates indirect communication between sprites or the stage.",
"inputs": {}, "fields": {"BROADCAST_OPTION": ["message1", "5O!nei;S$!c!=hCT}0:a"]}, "shadow": False, "topLevel": True
},
"event_broadcast": {
"block_name": "broadcast ()", "block_type": "Events", "block_shape": "Stack Block", "op_code": "event_broadcast",
"functionality": "Sends a broadcast message throughout the Scratch program, activating any 'when I receive ()' blocks that are set to listen for that message, enabling indirect communication.",
"inputs": {"BROADCAST_INPUT": [1, [11, "message1", "5O!nei;S$!c!=hCT}0:a"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"event_broadcastandwait": {
"block_name": "broadcast () and wait", "block_type": "Events", "block_shape": "Stack Block", "op_code": "event_broadcastandwait",
"functionality": "Sends a broadcast message and pauses the current script until all other scripts activated by that broadcast have completed their execution, ensuring sequential coordination.",
"inputs": {"BROADCAST_INPUT": [1, [11, "message1", "5O!nei;S$!c!=hCT}0:a"]]}, "fields": {}, "shadow": False, "topLevel": True
},
# looks_block.json
"looks_sayforsecs": {
"block_name": "say () for () seconds", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_sayforsecs",
"functionality": "Displays a speech bubble containing specified text for a set duration.",
"inputs": {"MESSAGE": [1, [10, "Hello!"]], "SECS": [1, [4, "2"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_say": {
"block_name": "say ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_say",
"functionality": "Displays a speech bubble with the specified text indefinitely until another 'say' or 'think' block is activated.",
"inputs": {"MESSAGE": [1, [10, "Hello!"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_thinkforsecs": {
"block_name": "think () for () seconds", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_thinkforsecs",
"functionality": "Displays a thought bubble containing specified text for a set duration.",
"inputs": {"MESSAGE": [1, [10, "Hmm..."]], "SECS": [1, [4, "2"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_think": {
"block_name": "think ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_think",
"functionality": "Displays a thought bubble with the specified text indefinitely until another 'say' or 'think' block is activated.",
"inputs": {"MESSAGE": [1, [10, "Hmm..."]]}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_switchcostumeto": {
"block_name": "switch costume to ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_switchcostumeto",
"functionality": "Alters the sprite's appearance to a designated costume.",
"inputs": {"COSTUME": [1, "looks_costume"]}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_costume": {
"block_name": "costume menu", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_costume",
"functionality": "Menu for switch costume to block.",
"inputs": {}, "fields": {"COSTUME": ["costume1", None]}, "shadow": True, "topLevel": False
},
"looks_nextcostume": {
"block_name": "next costume", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_nextcostume",
"functionality": "Switches the sprite's costume to the next one in its costume list. If it's the last costume, it cycles back to the first.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_switchbackdropto": {
"block_name": "switch backdrop to ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_switchbackdropto",
"functionality": "Changes the stage's backdrop to a specified backdrop.",
"inputs": {"BACKDROP": [1, "looks_backdrops"]}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_backdrops": {
"block_name": "backdrop menu", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_backdrops",
"functionality": "Menu for switch backdrop to block.",
"inputs": {}, "fields": {"BACKDROP": ["backdrop1", None]}, "shadow": True, "topLevel": False
},
"looks_switchbackdroptowait": {
"block_name": "switch backdrop to () and wait", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_switchbackdroptowait",
"functionality": "Changes the stage's backdrop to a specified backdrop and pauses the script until any 'When backdrop switches to' scripts for that backdrop have finished.",
"inputs": {"BACKDROP": [1, "looks_backdrops"]}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_nextbackdrop": {
"block_name": "next backdrop", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_nextbackdrop",
"functionality": "Switches the stage's backdrop to the next one in its backdrop list. If it's the last backdrop, it cycles back to the first.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_changesizeby": {
"block_name": "change size by ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_changesizeby",
"functionality": "Changes the sprite's size by a specified percentage. Positive values make it larger, negative values make it smaller.",
"inputs": {"CHANGE": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_setsizeto": {
"block_name": "set size to () %", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_setsizeto",
"functionality": "Sets the sprite's size to a specific percentage of its original size.",
"inputs": {"SIZE": [1, [4, "100"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_changeeffectby": {
"block_name": "change () effect by ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_changeeffectby",
"functionality": "Changes a visual effect on the sprite by a specified amount (e.g., color, fisheye, whirl, pixelate, mosaic, brightness, ghost).",
"inputs": {"CHANGE": [1, [4, "25"]]}, "fields": {"EFFECT": ["COLOR", None]}, "shadow": False, "topLevel": True
},
"looks_seteffectto": {
"block_name": "set () effect to ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_seteffectto",
"functionality": "Sets a visual effect on the sprite to a specific value.",
"inputs": {"VALUE": [1, [4, "0"]]}, "fields": {"EFFECT": ["COLOR", None]}, "shadow": False, "topLevel": True
},
"looks_cleargraphiceffects": {
"block_name": "clear graphic effects", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_cleargraphiceffects",
"functionality": "Removes all visual effects applied to the sprite.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_show": {
"block_name": "show", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_show",
"functionality": "Makes the sprite visible on the stage.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_hide": {
"block_name": "hide", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_hide",
"functionality": "Makes the sprite invisible on the stage.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"looks_gotofrontback": {
"block_name": "go to () layer", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_gotofrontback",
"functionality": "Moves the sprite to the front-most or back-most layer of other sprites on the stage.",
"inputs": {}, "fields": {"FRONT_BACK": ["front", None]}, "shadow": False, "topLevel": True
},
"looks_goforwardbackwardlayers": {
"block_name": "go () layers", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_goforwardbackwardlayers",
"functionality": "Moves the sprite forward or backward a specified number of layers in relation to other sprites.",
"inputs": {"NUM": [1, [7, "1"]]}, "fields": {"FORWARD_BACKWARD": ["forward", None]}, "shadow": False, "topLevel": True
},
"looks_costumenumbername": {
"block_name": "(costume ())", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_costumenumbername",
"functionality": "Reports the current costume's number or name.",
"inputs": {}, "fields": {"NUMBER_NAME": ["number", None]}, "shadow": False, "topLevel": True
},
"looks_backdropnumbername": {
"block_name": "(backdrop ())", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_backdropnumbername",
"functionality": "Reports the current backdrop's number or name.",
"inputs": {}, "fields": {"NUMBER_NAME": ["number", None]}, "shadow": False, "topLevel": True
},
"looks_size": {
"block_name": "(size)", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_size",
"functionality": "Reports the current size of the sprite as a percentage.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
# operator_block.json
"operator_add": {
"block_name": "(() + ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_add",
"functionality": "Adds two numerical values.",
"inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_subtract": {
"block_name": "(() - ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_subtract",
"functionality": "Subtracts the second numerical value from the first.",
"inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_multiply": {
"block_name": "(() * ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_multiply",
"functionality": "Multiplies two numerical values.",
"inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_divide": {
"block_name": "(() / ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_divide",
"functionality": "Divides the first numerical value by the second.",
"inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_random": {
"block_name": "(pick random () to ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_random",
"functionality": "Generates a random integer within a specified inclusive range.",
"inputs": {"FROM": [1, [4, "1"]], "TO": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_gt": {
"block_name": "<() > ()>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_gt",
"functionality": "Checks if the first value is greater than the second.",
"inputs": {"OPERAND1": [1, [10, ""]], "OPERAND2": [1, [10, "50"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_lt": {
"block_name": "<() < ()>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_lt",
"functionality": "Checks if the first value is less than the second.",
"inputs": {"OPERAND1": [1, [10, ""]], "OPERAND2": [1, [10, "50"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_equals": {
"block_name": "<() = ()>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_equals",
"functionality": "Checks if two values are equal.",
"inputs": {"OPERAND1": [1, [10, ""]], "OPERAND2": [1, [10, "50"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_and": {
"block_name": "<<> and <>>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_and",
"functionality": "Returns 'true' if both provided Boolean conditions are 'true'.",
"inputs": {"OPERAND1": [2, None], "OPERAND2": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_or": {
"block_name": "<<> or <>>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_or",
"functionality": "Returns 'true' if at least one of the provided Boolean conditions is 'true'.",
"inputs": {"OPERAND1": [2, None], "OPERAND2": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_not": {
"block_name": "<not <>>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_not",
"functionality": "Returns 'true' if the provided Boolean condition is 'false', and 'false' if it is 'true'.",
"inputs": {"OPERAND": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_join": {
"block_name": "(join ()())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_join",
"functionality": "Concatenates two strings or values into a single string.",
"inputs": {"STRING1": [1, [10, "apple "]], "STRING2": [1, [10, "banana"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_letterof": {
"block_name": "letter () of ()", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_letterof",
"functionality": "Reports the character at a specific numerical position within a string.",
"inputs": {"LETTER": [1, [6, "1"]], "STRING": [1, [10, "apple"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_length": {
"block_name": "(length of ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_length",
"functionality": "Reports the total number of characters in a given string.",
"inputs": {"STRING": [1, [10, "apple"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_contains": {
"block_name": "<() contains ()?>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_contains",
"functionality": "Checks if one string contains another string.",
"inputs": {"STRING1": [1, [10, "apple"]], "STRING2": [1, [10, "a"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_mod": {
"block_name": "(() mod ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_mod",
"functionality": "Reports the remainder when the first number is divided by the second.",
"inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_round": {
"block_name": "(round ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_round",
"functionality": "Rounds a numerical value to the nearest integer.",
"inputs": {"NUM": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
},
"operator_mathop": {
"block_name": "(() of ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_mathop",
"functionality": "Performs various mathematical functions (e.g., absolute value, square root, trigonometric functions).",
"inputs": {"NUM": [1, [4, ""]]}, "fields": {"OPERATOR": ["abs", None]}, "shadow": False, "topLevel": True
},
# sensing_block.json
"sensing_touchingobject": {
"block_name": "<touching [edge v]?>", "block_type": "Sensing", "op_code": "sensing_touchingobject", "block_shape": "Boolean Block",
"functionality": "Checks if its sprite is touching the mouse-pointer, edge, or another specified sprite.",
"inputs": {"TOUCHINGOBJECTMENU": [1, "sensing_touchingobjectmenu"]}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_touchingobjectmenu": {
"block_name": "touching object menu", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_touchingobjectmenu",
"functionality": "Menu for touching object block.",
"inputs": {}, "fields": {"TOUCHINGOBJECTMENU": ["_mouse_", None]}, "shadow": True, "topLevel": False
},
"sensing_touchingcolor": {
"block_name": "<touching color ()?>", "block_type": "Sensing", "op_code": "sensing_touchingcolor", "block_shape": "Boolean Block",
"functionality": "Checks whether its sprite is touching a specified color.",
"inputs": {"COLOR": [1, [9, "#55b888"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_coloristouchingcolor": {
"block_name": "<color () is touching ()?>", "block_type": "Sensing", "op_code": "sensing_coloristouchingcolor", "block_shape": "Boolean Block",
"functionality": "Checks whether a specific color on its sprite is touching another specified color on the stage or another sprite.",
"inputs": {"COLOR1": [1, [9, "#d019f2"]], "COLOR2": [1, [9, "#2b0de3"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_askandwait": {
"block_name": "Ask () and Wait", "block_type": "Sensing", "block_shape": "Stack Block", "op_code": "sensing_askandwait",
"functionality": "Displays an input box with specified text at the bottom of the screen, allowing users to input text, which is stored in the 'Answer' block.",
"inputs": {"QUESTION": [1, [10, "What's your name?"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_answer": {
"block_name": "(answer)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_answer",
"functionality": "Holds the most recent text inputted using the 'Ask () and Wait' block.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_keypressed": {
"block_name": "<key () pressed?>", "block_type": "Sensing", "op_code": "sensing_keypressed", "block_shape": "Boolean Block",
"functionality": "Checks if a specified keyboard key is currently being pressed.",
"inputs": {"KEY_OPTION": [1, "sensing_keyoptions"]}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_keyoptions": {
"block_name": "key options menu", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_keyoptions",
"functionality": "Menu for key pressed block.",
"inputs": {}, "fields": {"KEY_OPTION": ["space", None]}, "shadow": True, "topLevel": False
},
"sensing_mousedown": {
"block_name": "<mouse down?>", "block_type": "Sensing", "op_code": "sensing_mousedown", "block_shape": "Boolean Block",
"functionality": "Checks if the computer mouse's primary button is being clicked while the cursor is over the stage.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_mousex": {
"block_name": "(mouse x)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_mousex",
"functionality": "Reports the mouse-pointer’s current X position on the stage.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_mousey": {
"block_name": "(mouse y)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_mousey",
"functionality": "Reports the mouse-pointer’s current Y position on the stage.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_setdragmode": {
"block_name": "set drag mode [draggable v]", "block_type": "Sensing", "block_shape": "Stack Block", "op_code": "sensing_setdragmode",
"functionality": "Sets whether the sprite can be dragged by the mouse on the stage.",
"inputs": {}, "fields": {"DRAG_MODE": ["draggable", None]}, "shadow": False, "topLevel": True
},
"sensing_loudness": {
"block_name": "(loudness)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_loudness",
"functionality": "Reports the loudness of noise received by a microphone on a scale of 0 to 100.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_timer": {
"block_name": "(timer)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_timer",
"functionality": "Reports the elapsed time since Scratch was launched or the timer was reset, increasing by 1 every second.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_resettimer": {
"block_name": "Reset Timer", "block_type": "Sensing", "block_shape": "Stack Block", "op_code": "sensing_resettimer",
"functionality": "Sets the timer’s value back to 0.0.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_of": {
"block_name": "(() of ())", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_of",
"functionality": "Reports a specified value (e.g., x position, direction, costume number) of a specified sprite or the Stage to be accessed in current sprite or stage.",
"inputs": {"OBJECT": [1, "sensing_of_object_menu"]}, "fields": {"PROPERTY": ["backdrop #", None]}, "shadow": False, "topLevel": True
},
"sensing_of_object_menu": {
"block_name": "of object menu", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_of_object_menu",
"functionality": "Menu for of block.",
"inputs": {}, "fields": {"OBJECT": ["_stage_", None]}, "shadow": True, "topLevel": False
},
"sensing_current": {
"block_name": "(current ())", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_current",
"functionality": "Reports the current local year, month, date, day of the week, hour, minutes, or seconds.",
"inputs": {}, "fields": {"CURRENTMENU": ["YEAR", None]}, "shadow": False, "topLevel": True
},
"sensing_dayssince2000": {
"block_name": "(days since 2000)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_dayssince2000",
"functionality": "Reports the number of days (and fractions of a day) since 00:00:00 UTC on January 1, 2000.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sensing_username": {
"block_name": "(username)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_username",
"functionality": "Reports the username of the user currently logged into Scratch. If no user is logged in, it reports nothing.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
# sound_block.json
"sound_playuntildone": {
"block_name": "play sound () until done", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_playuntildone",
"functionality": "Plays a specified sound and pauses the script's execution until the sound has completed.",
"inputs": {"SOUND_MENU": [1, "sound_sounds_menu"]}, "fields": {}, "shadow": False, "topLevel": True
},
"sound_sounds_menu": {
"block_name": "sound menu", "block_type": "Sound", "block_shape": "Reporter Block", "op_code": "sound_sounds_menu",
"functionality": "Menu for sound blocks.",
"inputs": {}, "fields": {"SOUND_MENU": ["Meow", None]}, "shadow": True, "topLevel": False
},
"sound_play": {
"block_name": "start sound ()", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_play",
"functionality": "Initiates playback of a specified sound without pausing the script, allowing other actions to proceed concurrently.",
"inputs": {"SOUND_MENU": [1, "sound_sounds_menu"]}, "fields": {}, "shadow": False, "topLevel": True
},
"sound_stopallsounds": {
"block_name": "stop all sounds", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_stopallsounds",
"functionality": "Stops all currently playing sounds.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sound_changeeffectby": {
"block_name": "change () effect by ()", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_changeeffectby",
"functionality": "Changes the project's sound effect by a specified amount.",
"inputs": {"VALUE": [1, [4, "10"]]}, "fields": {"EFFECT": ["PITCH", None]}, "shadow": False, "topLevel": True
},
"sound_seteffectto": {
"block_name": "set () effect to ()", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_seteffectto",
"functionality": "Sets the sound effect to a specific value.",
"inputs": {"VALUE": [1, [4, "100"]]}, "fields": {"EFFECT": ["PITCH", None]}, "shadow": False, "topLevel": True
},
"sound_cleareffects": {
"block_name": "clear sound effects", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_cleareffects",
"functionality": "Removes all sound effects applied to the sprite.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
"sound_changevolumeby": {
"block_name": "change volume by ()", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_changevolumeby",
"functionality": "Changes the project's sound volume by a specified amount.",
"inputs": {"VOLUME": [1, [4, "-10"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"sound_setvolumeto": {
"block_name": "set volume to () %", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_setvolumeto",
"functionality": "Sets the sound volume to a specific percentage (0-100).",
"inputs": {"VOLUME": [1, [4, "100"]]}, "fields": {}, "shadow": False, "topLevel": True
},
"sound_volume": {
"block_name": "(volume)", "block_type": "Sound", "block_shape": "Reporter Block", "op_code": "sound_volume",
"functionality": "Reports the current volume level of the sprite.",
"inputs": {}, "fields": {}, "shadow": False, "topLevel": True
},
}
# Example input with opcodes for the initial generation
initial_opcode_counts = [
{"opcode":"event_whenflagclicked","count":1},
{"opcode":"motion_gotoxy","count":1},
{"opcode":"motion_glidesecstoxy","count":1},
{"opcode":"motion_xposition","count":1},
{"opcode":"motion_setx","count":1},
{"opcode":"control_forever","count":1},
{"opcode":"control_if","count":1},
{"opcode":"control_stop","count":1},
{"opcode":"operator_lt","count":1},
{"opcode":"sensing_touchingobject","count":1}, # Changed from sensing_istouching
{"opcode":"sensing_touchingobjectmenu","count":1},
{"opcode":"event_broadcast","count":1},
{"opcode":"data_setvariableto","count":2},
{"opcode":"data_showvariable","count":2},
]
# Generate the initial blocks and get the opcode_occurrences
generated_output_json, initial_opcode_occurrences = generate_blocks_from_opcodes(initial_opcode_counts, all_block_definitions)
# Pseudo-code to interpret
pseudo_code_input = """
when green flag clicked
go to x: (240) y: (-135)
set [score v] to (1)
set [speed v] to (1)
show variable [score v]
show variable [speed v]
forever
glide (2) seconds to x: (-240) y: (-135)
if <((x position)) < (-235)> then
set x to (240)
end
if <touching [Sprite1 v]?> then
broadcast [Game Over v]
stop [all v]
end
end
end
"""
# Interpret the pseudo-code and update the blocks, passing opcode_occurrences
final_generated_blocks = interpret_pseudo_code_and_update_blocks(generated_output_json, pseudo_code_input, all_block_definitions, initial_opcode_occurrences)
print(initial_opcode_occurrences)
#print(json.dumps(final_generated_blocks, indent=2))
# ```json
# {
# "event_whenflagclicked_1": {
# "block_name": "when green flag pressed",
# "block_type": "Events",
# "op_code": "event_whenflagclicked",
# "block_shape": "Hat Block",
# "functionality": "This Hat block initiates the script when the green flag is clicked, serving as the common starting point for most Scratch projects.",
# "inputs": {},
# "fields": {},
# "shadow": false,
# "topLevel": true,
# "parent": null,
# "next": "motion_gotoxy_1"
# },
# "motion_gotoxy_1": {
# "block_name": "go to x: () y: ()",
# "block_type": "Motion",
# "op_code": "motion_gotoxy",
# "functionality": "Moves the sprite to the specified X and Y coordinates on the stage.",
# "inputs": {
# "X": [
# 4,
# "240"
# ],
# "Y": [
# 4,
# "-135"
# ]
# },
# "fields": {},
# "shadow": false,
# "topLevel": false,
# "parent": null,
# "next": "data_setvariableto_1"
# },
# "motion_glidesecstoxy_1": {
# "block_name": "glide () secs to x: () y: ()",
# "block_type": "Motion",
# "op_code": "motion_glidesecstoxy",
# "functionality": "Glides the sprite smoothly to the specified X and Y coordinates over a given number of seconds.",
# "inputs": {
# "SECS": [
# 4,
# "2"
# ],
# "X": [
# 4,
# "-240"
# ],
# "Y": [
# 4,
# "-135"
# ]
# },
# "fields": {},
# "shadow": false,
# "topLevel": false,
# "parent": "control_forever_1",
# "next": "control_if_1"
# },
# "motion_xposition_1": {
# "block_name": "(x position)",
# "block_type": "Motion",
# "op_code": "motion_xposition",
# "functionality": "Reports the current X-coordinate of the sprite.[NOTE: not used in stage/backdrops]",
# "inputs": {},
# "fields": {},
# "shadow": true,
# "topLevel": false,
# "parent": "operator_lt_1",
# "next": null
# },
# "motion_setx_1": {
# "block_name": "set x to ()",
# "block_type": "Motion",
# "op_code": "motion_setx",
# "functionality": "Sets the sprite's X-coordinate to a specific value, placing it at a precise horizontal position.",
# "inputs": {
# "X": [
# 4,
# "240"
# ]
# },
# "fields": {},
# "shadow": false,
# "topLevel": false,
# "parent": "control_if_1",
# "next": null
# },
# "control_forever_1": {
# "block_name": "forever",
# "block_type": "Control",
# "op_code": "control_forever",
# "functionality": "Continuously runs the blocks inside it.",
# "inputs": {
# "SUBSTACK": [
# 2,
# "motion_glidesecstoxy_1"
# ]
# },
# "fields": {},
# "shadow": false,
# "topLevel": false,
# "parent": null,
# "next": null
# },
# "control_if_1": {
# "block_name": "if <> then",
# "block_type": "Control",
# "op_code": "control_if",
# "functionality": "Executes the blocks inside it only if the specified boolean condition is true. [NOTE: it takes boolean blocks as input]",
# "inputs": {
# "CONDITION": [
# 2,
# "operator_lt_1"
# ],
# "SUBSTACK": [
# 2,
# "motion_setx_1"
# ]
# },
# "fields": {},
# "shadow": false,
# "topLevel": false,
# "parent": "control_forever_1",
# "next": "control_if_2"
# },
# "control_stop_1": {
# "block_name": "stop [v]",
# "block_type": "Control",
# "op_code": "control_stop",
# "functionality": "Halts all scripts, only the current script, or other scripts within the same sprite. Its shape can dynamically change based on the selected option.",
# "inputs": {},
# "fields": {
# "STOP_OPTION": [
# "all",
# null
# ]
# },
# "shadow": false,
# "topLevel": false,
# "parent": "control_if_2",
# "mutation": {
# "tagName": "mutation",
# "children": [],
# "hasnext": "false"
# },
# "next": null
# },
# "operator_lt_1": {
# "block_name": "<() < ()>",
# "block_type": "operator",
# "op_code": "operator_lt",
# "functionality": "Checks if the first value is less than the second.",
# "inputs": {
# "OPERAND1": [
# 1,
# "motion_xposition_1"
# ],
# "OPERAND2": [
# 4,
# "-235"
# ]
# },
# "fields": {},
# "shadow": true,
# "topLevel": false,
# "parent": "control_if_1",
# "next": null
# },
# "sensing_touchingobject_1": {
# "block_name": "<touching [edge v]?>",
# "block_type": "Sensing",
# "op_code": "sensing_touchingobject",
# "functionality": "Checks if its sprite is touching the mouse-pointer, edge, or another specified sprite.",
# "inputs": {
# "TOUCHINGOBJECTMENU": [
# 1,
# "sensing_touchingobjectmenu_1"
# ]
# },
# "fields": {},
# "shadow": true,
# "topLevel": false,
# "parent": "control_if_2",
# "next": null
# },
# "sensing_touchingobjectmenu_1": {
# "block_name": "touching object menu",
# "block_type": "Sensing",
# "op_code": "sensing_touchingobjectmenu",
# "functionality": "Menu for touching object block.",
# "inputs": {},
# "fields": {
# "TOUCHINGOBJECTMENU": [
# "Sprite1",
# null
# ]
# },
# "shadow": true,
# "topLevel": false,
# "parent": "sensing_touchingobject_1",
# "next": null
# },
# "event_broadcast_1": {
# "block_name": "broadcast ()",
# "block_type": "Events",
# "op_code": "event_broadcast",
# "functionality": "Sends a broadcast message throughout the Scratch program, activating any 'when I receive ()' blocks that are set to listen for that message, enabling indirect communication.",
# "inputs": {
# "BROADCAST_INPUT": [
# 10,
# "Game Over"
# ]
# },
# "fields": {},
# "shadow": false,
# "topLevel": false,
# "parent": "control_if_2",
# "next": "control_stop_1"
# },
# "data_setvariableto_1": {
# "block_name": "set [my variable v] to ()",
# "block_type": "Data",
# "op_code": "data_setvariableto",
# "functionality": "Assigns a specific value (number, string, or boolean) to a variable.",
# "inputs": {
# "VALUE": [
# 4,
# "1"
# ]
# },
# "fields": {
# "VARIABLE": [
# "score",
# "`var_score"
# ]
# },
# "shadow": false,
# "topLevel": false,
# "parent": null,
# "next": "data_setvariableto_2"
# },
# "data_setvariableto_2": {
# "block_name": "set [my variable v] to ()",
# "block_type": "Data",
# "op_code": "data_setvariableto",
# "functionality": "Assigns a specific value (number, string, or boolean) to a variable.",
# "inputs": {
# "VALUE": [
# 4,
# "1"
# ]
# },
# "fields": {
# "VARIABLE": [
# "speed",
# "`var_speed"
# ]
# },
# "shadow": false,
# "topLevel": false,
# "parent": null,
# "next": "data_showvariable_1"
# },
# "data_showvariable_1": {
# "block_name": "show variable [my variable v]",
# "block_type": "Data",
# "op_code": "data_showvariable",
# "functionality": "Makes a variable's monitor visible on the stage.",
# "inputs": {},
# "fields": {
# "VARIABLE": [
# "score",
# "`var_score"
# ]
# },
# "shadow": false,
# "topLevel": false,
# "parent": null,
# "next": "data_showvariable_2"
# },
# "data_showvariable_2": {
# "block_name": "show variable [my variable v]",
# "block_type": "Data",
# "op_code": "data_showvariable",
# "functionality": "Makes a variable's monitor visible on the stage.",
# "inputs": {},
# "fields": {
# "VARIABLE": [
# "speed",
# "`var_speed"
# ]
# },
# "shadow": false,
# "topLevel": false,
# "parent": null,
# "next": "control_forever_1"
# },
# "control_if_2": {
# "block_name": "if <> then",
# "block_type": "Control",
# "op_code": "control_if",
# "functionality": "Executes the blocks inside it only if the specified boolean condition is true. [NOTE: it takes boolean blocks as input]",
# "inputs": {
# "CONDITION": [
# 2,
# "sensing_touchingobject_1"
# ],
# "SUBSTACK": [
# 2,
# "event_broadcast_1"
# ]
# },
# "fields": {},
# "shadow": false,
# "topLevel": false,
# "parent": "control_forever_1",
# "next": null
# }
# }