prthm11 commited on
Commit
6a0fe76
·
verified ·
1 Parent(s): b31d93c

Delete utils/script_plan.py

Browse files
Files changed (1) hide show
  1. utils/script_plan.py +0 -1449
utils/script_plan.py DELETED
@@ -1,1449 +0,0 @@
1
- import json
2
- import copy
3
- import re
4
-
5
- def generate_blocks_from_opcodes(opcode_counts, all_block_definitions):
6
- """
7
- Generates a dictionary of Scratch-like blocks based on a list of opcodes and a reference block definition.
8
- It now correctly links parent and menu blocks using their generated unique keys, and handles various block categories.
9
- It ensures that menu blocks are only generated as children of their respective parent blocks.
10
-
11
- Args:
12
- opcode_counts (list): An array of objects, each with an 'opcode' and 'count' property.
13
- Example: [{"opcode": "motion_gotoxy", "count": 1}]
14
- all_block_definitions (dict): A comprehensive dictionary containing definitions for all block types.
15
-
16
- Returns:
17
- tuple: A tuple containing:
18
- - dict: A JSON object where keys are generated block IDs and values are the block definitions.
19
- - dict: The opcode_occurrences dictionary for consistent unique key generation across functions.
20
- """
21
- generated_blocks = {}
22
- opcode_occurrences = {} # To keep track of how many times each opcode (main or menu) has been used for unique keys
23
-
24
- # Define explicit parent-menu relationships for linking purposes
25
- # This maps main_opcode -> list of (input_field_name, menu_opcode)
26
- explicit_menu_links = {
27
- "motion_goto": [("TO", "motion_goto_menu")],
28
- "motion_glideto": [("TO", "motion_glideto_menu")],
29
- "motion_pointtowards": [("TOWARDS", "motion_pointtowards_menu")],
30
- "sensing_keypressed": [("KEY_OPTION", "sensing_keyoptions")],
31
- "sensing_of": [("OBJECT", "sensing_of_object_menu")],
32
- "sensing_touchingobject": [("TOUCHINGOBJECTMENU", "sensing_touchingobjectmenu")],
33
- "control_create_clone_of": [("CLONE_OPTION", "control_create_clone_of_menu")],
34
- "sound_play": [("SOUND_MENU", "sound_sounds_menu")],
35
- "sound_playuntildone": [("SOUND_MENU", "sound_sounds_menu")],
36
- "looks_switchcostumeto": [("COSTUME", "looks_costume")],
37
- "looks_switchbackdropto": [("BACKDROP", "looks_backdrops")],
38
- }
39
-
40
- # --- Step 1: Process explicitly requested opcodes and generate their instances and associated menus ---
41
- for item in opcode_counts:
42
- opcode = item.get("opcode")
43
- count = item.get("count", 1)
44
-
45
- # Special handling for 'sensing_istouching' which maps to 'sensing_touchingobject'
46
- if opcode == "sensing_istouching":
47
- opcode = "sensing_touchingobject"
48
-
49
- if not opcode:
50
- print("Warning: Skipping item with missing 'opcode'.")
51
- continue
52
-
53
- if opcode not in all_block_definitions:
54
- print(f"Warning: Opcode '{opcode}' not found in all_block_definitions. Skipping.")
55
- continue
56
-
57
- for _ in range(count):
58
- # Increment occurrence count for the current main opcode
59
- opcode_occurrences[opcode] = opcode_occurrences.get(opcode, 0) + 1
60
- main_block_instance_num = opcode_occurrences[opcode]
61
-
62
- main_block_unique_key = f"{opcode}_{main_block_instance_num}"
63
-
64
- # Create a deep copy of the main block definition
65
- main_block_data = copy.deepcopy(all_block_definitions[opcode])
66
-
67
- # Set properties for a top-level main block
68
- main_block_data["parent"] = None
69
- main_block_data["next"] = None
70
- main_block_data["topLevel"] = True
71
- main_block_data["shadow"] = False # Main blocks are typically not shadows
72
-
73
- generated_blocks[main_block_unique_key] = main_block_data
74
-
75
- # If this main block has associated menus, generate and link them now
76
- if opcode in explicit_menu_links:
77
- for input_field_name, menu_opcode_type in explicit_menu_links[opcode]:
78
- if menu_opcode_type in all_block_definitions:
79
- # Increment the occurrence for the menu block type
80
- opcode_occurrences[menu_opcode_type] = opcode_occurrences.get(menu_opcode_type, 0) + 1
81
- menu_block_instance_num = opcode_occurrences[menu_opcode_type]
82
-
83
- menu_block_data = copy.deepcopy(all_block_definitions[menu_opcode_type])
84
-
85
- # Generate a unique key for this specific menu instance
86
- menu_unique_key = f"{menu_opcode_type}_{menu_block_instance_num}"
87
-
88
- # Set properties for a shadow menu block
89
- menu_block_data["shadow"] = True
90
- menu_block_data["topLevel"] = False
91
- menu_block_data["next"] = None
92
- menu_block_data["parent"] = main_block_unique_key # Link menu to its parent instance
93
-
94
- # Update the main block's input to point to this unique menu instance
95
- if input_field_name in main_block_data.get("inputs", {}) and \
96
- isinstance(main_block_data["inputs"][input_field_name], list) and \
97
- len(main_block_data["inputs"][input_field_name]) > 1 and \
98
- main_block_data["inputs"][input_field_name][0] == 1:
99
-
100
- main_block_data["inputs"][input_field_name][1] = menu_unique_key
101
-
102
- generated_blocks[menu_unique_key] = menu_block_data
103
-
104
- return generated_blocks, opcode_occurrences
105
-
106
- def interpret_pseudo_code_and_update_blocks(generated_blocks_json, pseudo_code, all_block_definitions, opcode_occurrences):
107
- """
108
- Interprets pseudo-code to update the generated Scratch blocks, replacing static values
109
- with dynamic values and establishing stacking/nesting logic.
110
-
111
- Args:
112
- generated_blocks_json (dict): The JSON object of pre-generated blocks.
113
- pseudo_code (str): The pseudo-code string to interpret.
114
- all_block_definitions (dict): A comprehensive dictionary containing definitions for all block types.
115
- opcode_occurrences (dict): A dictionary to keep track of opcode occurrences for unique key generation.
116
-
117
- Returns:
118
- dict: The updated JSON object of Scratch blocks.
119
- """
120
- updated_blocks = copy.deepcopy(generated_blocks_json)
121
-
122
- # Helper to create a new block instance (used for shadows/nested blocks)
123
- def create_block_instance_for_parsing(opcode, parent_key=None, is_shadow=False, is_top_level=False):
124
- opcode_occurrences[opcode] = opcode_occurrences.get(opcode, 0) + 1
125
- unique_key = f"{opcode}_{opcode_occurrences[opcode]}"
126
-
127
- new_block = copy.deepcopy(all_block_definitions.get(opcode, {}))
128
- if not new_block:
129
- print(f"Error: Definition for opcode '{opcode}' not found when creating instance for parsing.")
130
- return None, None
131
-
132
- new_block["parent"] = parent_key
133
- new_block["next"] = None
134
- new_block["topLevel"] = is_top_level
135
- new_block["shadow"] = is_shadow
136
-
137
- # Initialize inputs/fields to default empty values, but preserve structure
138
- if "inputs" in new_block:
139
- for input_name, input_data in new_block["inputs"].items():
140
- if isinstance(input_data, list) and len(input_data) > 1:
141
- if input_data[0] == 1: # Block reference
142
- new_block["inputs"][input_name][1] = None # Placeholder for linked block ID
143
- elif input_data[0] in [4, 5, 6, 7, 8, 9, 10]: # Literal types
144
- new_block["inputs"][input_name][1] = "" # Default empty literal
145
- if "fields" in new_block:
146
- for field_name, field_data in new_block["fields"].items():
147
- if isinstance(field_data, list) and len(field_data) > 0:
148
- new_block["fields"][field_name][0] = "" # Default empty field value
149
-
150
- updated_blocks[unique_key] = new_block
151
- return unique_key, new_block
152
-
153
- # Helper to parse input values from pseudo-code and create nested blocks if necessary
154
- def parse_and_link_input(parent_block_key, input_type, pseudo_value, input_name_in_parent=None, field_name_in_parent=None):
155
- pseudo_value = pseudo_value.strip()
156
-
157
- # 1. Handle literal numbers (e.g., "2", "+1", "-135")
158
- if re.fullmatch(r"[-+]?\d+(\.\d+)?", pseudo_value):
159
- return [4, pseudo_value] # Type 4 for number literal
160
-
161
- # 2. Handle literal strings (e.g., "Game Over") - often in quotes or simply text
162
- # If it's a broadcast message, it's typically a string literal.
163
- # If it's a 'say' message, it's a string literal.
164
- # If it's a variable name, it's handled by specific patterns later.
165
- if pseudo_value.startswith('"') and pseudo_value.endswith('"'):
166
- return [10, pseudo_value.strip('"')] # Type 10 for string literal
167
-
168
- # 3. Handle variable names (e.g., "[score v]", "[Sprite1 v]", "[Game Over v]")
169
- # These can be fields or inputs that expect a variable reporter block.
170
- var_match = re.match(r"\[(.+?) v\]", pseudo_value)
171
- if var_match:
172
- var_name = var_match.group(1).strip()
173
- # If it's a field (like for set variable, show variable)
174
- if field_name_in_parent:
175
- return var_name # Return name, parent block will set its field
176
- # If it's an input that expects a variable reporter (e.g., 'say (score)')
177
- # Create a data_variable shadow block
178
- var_reporter_key, var_reporter_data = create_block_instance_for_parsing(
179
- "data_variable", parent_key=parent_block_key, is_shadow=True
180
- )
181
- if var_reporter_key:
182
- var_reporter_data["fields"]["VARIABLE"] = [var_name, f"`var_{var_name}"] # Placeholder ID
183
- return [1, var_reporter_key] # Type 1 for block reference
184
- else:
185
- print(f"Warning: Could not create data_variable block for '{var_name}'")
186
- return [10, var_name] # Fallback to string literal
187
-
188
- # 4. Handle nested reporter blocks (e.g., "(x position)")
189
- reporter_match = re.match(r"\((.+?)\)", pseudo_value)
190
- if reporter_match:
191
- inner_content = reporter_match.group(1).strip()
192
- # Check if it's a known reporter block (like "x position")
193
- if inner_content in reporter_opcode_lookup:
194
- reporter_opcode = reporter_opcode_lookup[inner_content]
195
- reporter_block_key, reporter_block_data = create_block_instance_for_parsing(
196
- reporter_opcode, parent_key=parent_block_key, is_shadow=True
197
- )
198
- if reporter_block_key:
199
- return [1, reporter_block_key] # Type 1 for block reference
200
- else:
201
- print(f"Warning: Could not create reporter block for '{inner_content}'")
202
- return [10, inner_content] # Fallback to string literal
203
- else: # It's a literal number or string inside parentheses
204
- return parse_and_link_input(parent_block_key, input_type, inner_content) # Recurse for inner content
205
-
206
- # 5. Handle nested boolean blocks (e.g., "<(...) < (...)>")
207
- boolean_match = re.match(r"<(.+?)>", pseudo_value)
208
- if boolean_match:
209
- inner_condition_str = boolean_match.group(1).strip()
210
- # This is typically handled by the parent block's parsing (e.g., control_if)
211
- # For now, if called directly, it implies a boolean reporter.
212
- # We'll need specific logic for operator_lt, operator_and, etc.
213
- # This part is complex and often handled by the parent block's specific regex.
214
- # For this problem, the 'if' block's logic will create the boolean shadow.
215
- print(f"Warning: Direct parsing of standalone boolean '{pseudo_value}' not fully supported here.")
216
- return [10, pseudo_value] # Fallback to string literal
217
-
218
- # Default to string literal if no other pattern matches
219
- return [10, pseudo_value]
220
-
221
- lines = [line.strip() for line in pseudo_code.strip().split('\n') if line.strip()]
222
-
223
- # Track the current script and nesting
224
- current_script_head = None
225
- block_stack = [] # Stores (parent_block_key, indent_level, last_child_key_in_scope)
226
-
227
- # Create a mapping from block name patterns to their opcodes and input/field details
228
- # The 'input_map' keys are the internal Scratch input names, values are regex group indices.
229
- # The 'field_map' keys are the internal Scratch field names, values are regex group indices.
230
- # 'condition_opcode' is for 'if' blocks that take a specific boolean reporter.
231
- pseudo_code_to_opcode_map = {
232
- re.compile(r"when green flag clicked"): {"opcode": "event_whenflagclicked"},
233
- re.compile(r"go to x: \((.+?)\) y: \((.+?)\)"): {"opcode": "motion_gotoxy", "input_map": {"X": 0, "Y": 1}},
234
- re.compile(r"set \[(.+?) v\] to (.+)"): {"opcode": "data_setvariableto", "field_map": {"VARIABLE": 0}, "input_map": {"VALUE": 1}},
235
- re.compile(r"show variable \[(.+?) v\]"): {"opcode": "data_showvariable", "field_map": {"VARIABLE": 0}},
236
- re.compile(r"forever"): {"opcode": "control_forever"},
237
- re.compile(r"glide \((.+?)\) seconds to x: \((.+?)\) y: \((.+?)\)"): {"opcode": "motion_glidesecstoxy", "input_map": {"SECS": 0, "X": 1, "Y": 2}},
238
- re.compile(r"if <\((.+)\) < \((.+)\)> then"): {"opcode": "control_if", "condition_type": "operator_lt", "condition_input_map": {"OPERAND1": 0, "OPERAND2": 1}},
239
- re.compile(r"set x to \((.+?)\)"): {"opcode": "motion_setx", "input_map": {"X": 0}},
240
- re.compile(r"if <touching \[(.+?) v\]\?> then"): {"opcode": "control_if", "condition_type": "sensing_touchingobject", "condition_field_map": {"TOUCHINGOBJECTMENU": 0}},
241
- re.compile(r"broadcast \[(.+?) v\]"): {"opcode": "event_broadcast", "input_map": {"BROADCAST_INPUT": 0}},
242
- re.compile(r"stop \[(.+?) v\]"): {"opcode": "control_stop", "field_map": {"STOP_OPTION": 0}},
243
- re.compile(r"end"): {"opcode": "end_block"}, # Special marker for script end/C-block end
244
- }
245
-
246
- # Create a reverse lookup for reporter block opcodes based on their pseudo-code representation
247
- reporter_opcode_lookup = {}
248
- for opcode, definition in all_block_definitions.items():
249
- if definition.get("block_shape") == "Reporter Block":
250
- block_name = definition.get("block_name")
251
- if block_name:
252
- # Clean up block name for matching: remove parentheses, 'v' for variable, etc.
253
- clean_name = block_name.replace("(", "").replace(")", "").replace("[", "").replace("]", "").replace(" v", "").strip()
254
- reporter_opcode_lookup[clean_name] = opcode
255
- # Add specific entries for common reporters if their pseudo-code differs from clean_name
256
- if opcode == "motion_xposition":
257
- reporter_opcode_lookup["x position"] = opcode
258
- elif opcode == "motion_yposition":
259
- reporter_opcode_lookup["y position"] = opcode
260
- # Add more as needed based on pseudo-code patterns
261
-
262
- for line_idx, raw_line in enumerate(lines):
263
- current_line_indent = len(raw_line) - len(raw_line.lstrip())
264
- line = raw_line.strip()
265
-
266
- # Adjust block_stack based on current indent level
267
- while block_stack and current_line_indent <= block_stack[-1][1]:
268
- block_stack.pop()
269
-
270
- matched_block_info = None
271
- matched_values = None
272
-
273
- # Try to match the line against known block patterns
274
- for pattern_regex, info in pseudo_code_to_opcode_map.items():
275
- match = pattern_regex.match(line)
276
- if match:
277
- matched_block_info = info
278
- matched_values = match.groups()
279
- break
280
-
281
- if not matched_block_info:
282
- print(f"Warning: Could not interpret line: '{line}' at line {line_idx + 1}")
283
- continue
284
-
285
- opcode = matched_block_info["opcode"]
286
-
287
- # Handle 'end' block separately as it signifies closing a C-block
288
- if opcode == "end_block":
289
- # This 'end' matches the most recent C-block on the stack.
290
- # The while loop at the beginning of the iteration already handles popping.
291
- continue
292
-
293
- parent_key = None
294
- if block_stack:
295
- parent_key = block_stack[-1][0] # The last block on the stack is the parent
296
-
297
- # Create the new block instance
298
- new_block_key, new_block_data = create_block_instance_for_parsing(
299
- opcode,
300
- parent_key=parent_key,
301
- is_top_level=(parent_key is None)
302
- )
303
- if not new_block_key:
304
- continue
305
-
306
- # Link to previous block in the same script/nesting level
307
- if block_stack:
308
- # Update the 'next' of the previous block in the current scope
309
- last_child_key_in_scope = block_stack[-1][2] if len(block_stack[-1]) > 2 else None
310
- if last_child_key_in_scope and last_child_key_in_scope in updated_blocks:
311
- updated_blocks[last_child_key_in_scope]["next"] = new_block_key
312
-
313
- # Update the last child in the current scope
314
- block_stack[-1] = (block_stack[-1][0], block_stack[-1][1], new_block_key)
315
-
316
- # Populate inputs and fields based on matched_block_info and matched_values
317
- if matched_values:
318
- # Handle fields
319
- if "field_map" in matched_block_info:
320
- for field_name, group_idx in matched_block_info["field_map"].items():
321
- pseudo_field_value = matched_values[group_idx].replace(' v', '').strip()
322
- if field_name == "VARIABLE":
323
- # For variable fields, the actual variable ID is often derived or generated.
324
- # For now, we use a placeholder and the name.
325
- new_block_data["fields"][field_name] = [pseudo_field_value, f"`var_{pseudo_field_value}"]
326
- elif field_name == "STOP_OPTION":
327
- new_block_data["fields"][field_name] = [pseudo_field_value, None] # No ID needed for dropdown option
328
- else:
329
- new_block_data["fields"][field_name][0] = pseudo_field_value
330
-
331
- # Handle inputs
332
- if "input_map" in matched_block_info:
333
- for input_name, group_idx in matched_block_info["input_map"].items():
334
- pseudo_input_value = matched_values[group_idx].strip()
335
-
336
- 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)
337
-
338
- if parsed_input_info:
339
- if parsed_input_info[0] == 1: # It's a linked block (shadow reporter/boolean/menu)
340
- new_block_data["inputs"][input_name][1] = parsed_input_info[1] # Link block ID
341
- new_block_data["inputs"][input_name][0] = parsed_input_info[0] # Set type to 1 (block)
342
- else: # It's a literal value
343
- new_block_data["inputs"][input_name][1] = parsed_input_info[1]
344
- new_block_data["inputs"][input_name][0] = parsed_input_info[0] # Set appropriate type (4 for number, 10 for string)
345
-
346
- # Special handling for 'if' block conditions
347
- if opcode == "control_if":
348
- condition_type = matched_block_info.get("condition_type")
349
- if condition_type:
350
- condition_block_key, condition_block_data = create_block_instance_for_parsing(
351
- condition_type, parent_key=new_block_key, is_shadow=True
352
- )
353
- if condition_block_key:
354
- new_block_data["inputs"]["CONDITION"] = [2, condition_block_key] # Type 2 for boolean block reference
355
-
356
- # Populate inputs for the condition block (e.g., operator_lt)
357
- if "condition_input_map" in matched_block_info:
358
- for cond_input_name, cond_group_idx in matched_block_info["condition_input_map"].items():
359
- pseudo_cond_value = matched_values[cond_group_idx].strip()
360
- parsed_cond_input_info = parse_and_link_input(condition_block_key, condition_block_data["inputs"][cond_input_name][0], pseudo_cond_value)
361
- if parsed_cond_input_info:
362
- if parsed_cond_input_info[0] == 1:
363
- condition_block_data["inputs"][cond_input_name][1] = parsed_cond_input_info[1]
364
- condition_block_data["inputs"][cond_input_name][0] = parsed_cond_input_info[0]
365
- else:
366
- condition_block_data["inputs"][cond_input_name][1] = parsed_cond_input_info[1]
367
- condition_block_data["inputs"][cond_input_name][0] = parsed_cond_input_info[0]
368
-
369
- # Populate fields for the condition block (e.g., sensing_touchingobject's menu)
370
- if "condition_field_map" in matched_block_info:
371
- for cond_field_name, cond_group_idx in matched_block_info["condition_field_map"].items():
372
- pseudo_cond_field_value = matched_values[cond_group_idx].replace(' v', '').strip()
373
- if cond_field_name == "TOUCHINGOBJECTMENU":
374
- # Create the menu block for TOUCHINGOBJECTMENU
375
- menu_opcode = "sensing_touchingobjectmenu"
376
- menu_key, menu_data = create_block_instance_for_parsing(
377
- menu_opcode,
378
- parent_key=condition_block_key,
379
- is_shadow=True
380
- )
381
- if menu_key:
382
- condition_block_data["inputs"]["TOUCHINGOBJECTMENU"] = [1, menu_key] # Link to menu block
383
- menu_data["fields"]["TOUCHINGOBJECTMENU"] = [pseudo_cond_field_value, None] # Set menu value
384
- else:
385
- print(f"Warning: Could not create menu block for touching object: '{pseudo_cond_field_value}'")
386
- else:
387
- condition_block_data["fields"][cond_field_name][0] = pseudo_cond_field_value
388
- else:
389
- print(f"Warning: Could not create condition block '{condition_type}' for 'if' statement.")
390
-
391
-
392
- # For C-blocks, push onto stack to track nesting
393
- # 'control_if' is a C-block, but its 'next' is inside its substack.
394
- # 'control_forever' is also a C-block.
395
- if all_block_definitions[opcode].get("block_shape") == "C-Block" and opcode != "control_if":
396
- # For C-blocks, the 'next' of the parent is usually null, and children start in 'SUBSTACK'
397
- # We add the block to the stack, and its "next" will be its first child.
398
- # The 'next' of the *last child* in its substack will point to the block after the C-block.
399
- block_stack.append((new_block_key, current_line_indent, None)) # (parent_key, indent, last_child_key_in_substack)
400
-
401
- # For C-blocks, the first child is linked via the 'SUBSTACK' input
402
- new_block_data["inputs"]["SUBSTACK"] = [2, None] # Placeholder for the first child block ID
403
-
404
- # For 'if' blocks, the 'next' of the parent is usually null, and children start in 'SUBSTACK'
405
- if opcode == "control_if":
406
- block_stack.append((new_block_key, current_line_indent, None))
407
- new_block_data["inputs"]["SUBSTACK"] = [2, None] # Placeholder for the first child block ID
408
-
409
-
410
- # Final pass to ensure topLevel is correctly set for the very first block of a script
411
- for key, block in updated_blocks.items():
412
- if block.get("parent") is None and block.get("next") is not None:
413
- block["topLevel"] = True
414
- elif block.get("parent") is None and block.get("next") is None and block.get("opcode") == "event_whenflagclicked":
415
- block["topLevel"] = True # Ensure hat blocks are always topLevel
416
-
417
- return updated_blocks
418
-
419
- # --- Consolidated Block Definitions from all provided JSONs ---
420
- # This dictionary should contain ALL block definitions from your JSON files.
421
- # I'm using the provided definitions from the previous turn.
422
- all_block_definitions = {
423
- # motion_block.json
424
- "motion_movesteps": {
425
- "block_name": "move () steps", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_movesteps",
426
- "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.",
427
- "inputs": {"STEPS": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
428
- },
429
- "motion_turnright": {
430
- "block_name": "turn right () degrees", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_turnright",
431
- "functionality": "Turns the sprite clockwise by the specified number of degrees.",
432
- "inputs": {"DEGREES": [1, [4, "15"]]}, "fields": {}, "shadow": False, "topLevel": True
433
- },
434
- "motion_turnleft": {
435
- "block_name": "turn left () degrees", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_turnleft",
436
- "functionality": "Turns the sprite counter-clockwise by the specified number of degrees.",
437
- "inputs": {"DEGREES": [1, [4, "15"]]}, "fields": {}, "shadow": False, "topLevel": True
438
- },
439
- "motion_goto": {
440
- "block_name": "go to ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_goto",
441
- "functionality": "Moves the sprite to a specified location, which can be a random position or at the mouse pointer or another to the sprite.",
442
- "inputs": {"TO": [1, "motion_goto_menu"]}, "fields": {}, "shadow": False, "topLevel": True
443
- },
444
- "motion_goto_menu": {
445
- "block_name": "go to menu", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_goto_menu",
446
- "functionality": "Menu for go to block.",
447
- "inputs": {}, "fields": {"TO": ["_random_", None]}, "shadow": True, "topLevel": False
448
- },
449
- "motion_gotoxy": {
450
- "block_name": "go to x: () y: ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_gotoxy",
451
- "functionality": "Moves the sprite to the specified X and Y coordinates on the stage.",
452
- "inputs": {"X": [1, [4, "0"]], "Y": [1, [4, "0"]]}, "fields": {}, "shadow": False, "topLevel": True
453
- },
454
- "motion_glideto": {
455
- "block_name": "glide () secs to ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_glideto",
456
- "functionality": "Glides the sprite smoothly to a specified location (random position, mouse pointer, or another sprite) over a given number of seconds.",
457
- "inputs": {"SECS": [1, [4, "1"]], "TO": [1, "motion_glideto_menu"]}, "fields": {}, "shadow": False, "topLevel": True
458
- },
459
- "motion_glideto_menu": {
460
- "block_name": "glide to menu", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_glideto_menu",
461
- "functionality": "Menu for glide to block.",
462
- "inputs": {}, "fields": {"TO": ["_random_", None]}, "shadow": True, "topLevel": False
463
- },
464
- "motion_glidesecstoxy": {
465
- "block_name": "glide () secs to x: () y: ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_glidesecstoxy",
466
- "functionality": "Glides the sprite smoothly to the specified X and Y coordinates over a given number of seconds.",
467
- "inputs": {"SECS": [1, [4, "1"]], "X": [1, [4, "0"]], "Y": [1, [4, "0"]]}, "fields": {}, "shadow": False, "topLevel": True
468
- },
469
- "motion_pointindirection": {
470
- "block_name": "point in direction ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_pointindirection",
471
- "functionality": "Sets the sprite's direction to a specified angle in degrees (0 = up, 90 = right, 180 = down, -90 = left).",
472
- "inputs": {"DIRECTION": [1, [8, "90"]]}, "fields": {}, "shadow": False, "topLevel": True
473
- },
474
- "motion_pointtowards": {
475
- "block_name": "point towards ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_pointtowards",
476
- "functionality": "Points the sprite towards the mouse pointer or another specified sprite.",
477
- "inputs": {"TOWARDS": [1, "motion_pointtowards_menu"]}, "fields": {}, "shadow": False, "topLevel": True
478
- },
479
- "motion_pointtowards_menu": {
480
- "block_name": "point towards menu", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_pointtowards_menu",
481
- "functionality": "Menu for point towards block.",
482
- "inputs": {}, "fields": {"TOWARDS": ["_mouse_", None]}, "shadow": True, "topLevel": False
483
- },
484
- "motion_changexby": {
485
- "block_name": "change x by ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_changexby",
486
- "functionality": "Changes the sprite's X-coordinate by the specified amount, moving it horizontally.",
487
- "inputs": {"DX": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
488
- },
489
- "motion_setx": {
490
- "block_name": "set x to ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_setx",
491
- "functionality": "Sets the sprite's X-coordinate to a specific value, placing it at a precise horizontal position.",
492
- "inputs": {"X": [1, [4, "0"]]}, "fields": {}, "shadow": False, "topLevel": True
493
- },
494
- "motion_changeyby": {
495
- "block_name": "change y by ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_changeyby",
496
- "functionality": "Changes the sprite's Y-coordinate by the specified amount, moving it vertically.",
497
- "inputs": {"DY": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
498
- },
499
- "motion_sety": {
500
- "block_name": "set y to ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_sety",
501
- "functionality": "Sets the sprite's Y-coordinate to a specific value, placing it at a precise vertical position.",
502
- "inputs": {"Y": [1, [4, "0"]]}, "fields": {}, "shadow": False, "topLevel": True
503
- },
504
- "motion_ifonedgebounce": {
505
- "block_name": "if on edge, bounce", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_ifonedgebounce",
506
- "functionality": "Reverses the sprite's direction if it touches the edge of the stage.",
507
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
508
- },
509
- "motion_setrotationstyle": {
510
- "block_name": "set rotation style ()", "block_type": "Motion", "block_shape": "Stack Block", "op_code": "motion_setrotationstyle",
511
- "functionality": "Determines how the sprite rotates: 'left-right' (flips horizontally), 'don't rotate' (stays facing one direction), or 'all around' (rotates freely).",
512
- "inputs": {}, "fields": {"STYLE": ["left-right", None]}, "shadow": False, "topLevel": True
513
- },
514
- "motion_xposition": {
515
- "block_name": "(x position)", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_xposition",
516
- "functionality": "Reports the current X-coordinate of the sprite.[NOTE: not used in stage/backdrops]",
517
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
518
- },
519
- "motion_yposition": {
520
- "block_name": "(y position)", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_yposition",
521
- "functionality": "Reports the current Y coordinate of the sprite on the stage.[NOTE: not used in stage/backdrops]",
522
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
523
- },
524
- "motion_direction": {
525
- "block_name": "(direction)", "block_type": "Motion", "block_shape": "Reporter Block", "op_code": "motion_direction",
526
- "functionality": "Reports the current direction of the sprite in degrees (0 = up, 90 = right, 180 = down, -90 = left).[NOTE: not used in stage/backdrops]",
527
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
528
- },
529
-
530
- # control_block.json
531
- "control_wait": {
532
- "block_name": "wait () seconds", "block_type": "Control", "block_shape": "Stack Block", "op_code": "control_wait",
533
- "functionality": "Pauses the script for a specified duration.",
534
- "inputs": {"DURATION": [1, [5, "1"]]}, "fields": {}, "shadow": False, "topLevel": True
535
- },
536
- "control_repeat": {
537
- "block_name": "repeat ()", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_repeat",
538
- "functionality": "Repeats the blocks inside it a specified number of times.",
539
- "inputs": {"TIMES": [1, [6, "10"]], "SUBSTACK": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
540
- },
541
- "control_forever": {
542
- "block_name": "forever", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_forever",
543
- "functionality": "Continuously runs the blocks inside it.",
544
- "inputs": {"SUBSTACK": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
545
- },
546
- "control_if": {
547
- "block_name": "if <> then", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_if",
548
- "functionality": "Executes the blocks inside it only if the specified boolean condition is true. [NOTE: it takes boolean blocks as input]",
549
- "inputs": {"CONDITION": [2, None], "SUBSTACK": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
550
- },
551
- "control_if_else": {
552
- "block_name": "if <> then else", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_if_else",
553
- "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]",
554
- "inputs": {"CONDITION": [2, None], "SUBSTACK": [2, None], "SUBSTACK2": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
555
- },
556
- "control_wait_until": {
557
- "block_name": "wait until <>", "block_type": "Control", "block_shape": "Stack Block", "op_code": "control_wait_until",
558
- "functionality": "Pauses the script until the specified boolean condition becomes true. [NOTE: it takes boolean blocks as input]",
559
- "inputs": {"CONDITION": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
560
- },
561
- "control_repeat_until": {
562
- "block_name": "repeat until <>", "block_type": "Control", "block_shape": "C-Block", "op_code": "control_repeat_until",
563
- "functionality": "Repeats the blocks inside it until the specified boolean condition becomes true. [NOTE: it takes boolean blocks as input]",
564
- "inputs": {"CONDITION": [2, None], "SUBSTACK": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
565
- },
566
- "control_stop": {
567
- "block_name": "stop [v]", "block_type": "Control", "block_shape": "Cap Block", "op_code": "control_stop",
568
- "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.",
569
- "inputs": {}, "fields": {"STOP_OPTION": ["all", None]}, "shadow": False, "topLevel": True, "mutation": {"tagName": "mutation", "children": [], "hasnext": "false"}
570
- },
571
- "control_start_as_clone": {
572
- "block_name": "When I Start as a Clone", "block_type": "Control", "block_shape": "Hat Block", "op_code": "control_start_as_clone",
573
- "functionality": "This Hat block initiates the script when a clone of the sprite is created. It defines the behavior of individual clones.",
574
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
575
- },
576
- "control_create_clone_of": {
577
- "block_name": "create clone of ()", "block_type": "Control", "block_shape": "Stack Block", "op_code": "control_create_clone_of",
578
- "functionality": "Generates a copy, or clone, of a specified sprite (or 'myself' for the current sprite).",
579
- "inputs": {"CLONE_OPTION": [1, "control_create_clone_of_menu"]}, "fields": {}, "shadow": False, "topLevel": True
580
- },
581
- "control_create_clone_of_menu": {
582
- "block_name": "create clone of menu", "block_type": "Control", "block_shape": "Reporter Block", "op_code": "control_create_clone_of_menu",
583
- "functionality": "Menu for create clone of block.",
584
- "inputs": {}, "fields": {"CLONE_OPTION": ["_myself_", None]}, "shadow": True, "topLevel": False
585
- },
586
- "control_delete_this_clone": {
587
- "block_name": "delete this clone", "block_type": "Control", "block_shape": "Cap Block", "op_code": "control_delete_this_clone",
588
- "functionality": "Removes the clone that is executing it from the stage.",
589
- "inputs":None, "fields": {}, "shadow": False, "topLevel": True
590
- },
591
-
592
- # data_block.json
593
- "data_setvariableto": {
594
- "block_name": "set [my variable v] to ()", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_setvariableto",
595
- "functionality": "Assigns a specific value (number, string, or boolean) to a variable.",
596
- "inputs": {"VALUE": [1, [10, "0"]]}, "fields": {"VARIABLE": ["my variable", "`jEk@4|i[#Fk?(8x)AV.-my variable"]}, "shadow": False, "topLevel": True
597
- },
598
- "data_changevariableby": {
599
- "block_name": "change [my variable v] by ()", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_changevariableby",
600
- "functionality": "Increases or decreases a variable's numerical value by a specified amount.",
601
- "inputs": {"VALUE": [1, [4, "1"]]}, "fields": {"VARIABLE": ["my variable", "`jEk@4|i[#Fk?(8x)AV.-my variable"]}, "shadow": False, "topLevel": True
602
- },
603
- "data_showvariable": {
604
- "block_name": "show variable [my variable v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_showvariable",
605
- "functionality": "Makes a variable's monitor visible on the stage.",
606
- "inputs": {}, "fields": {"VARIABLE": ["my variable", "`jEk@4|i[#Fk?(8x)AV.-my variable"]}, "shadow": False, "topLevel": True
607
- },
608
- "data_hidevariable": {
609
- "block_name": "hide variable [my variable v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_hidevariable",
610
- "functionality": "Hides a variable's monitor from the stage.",
611
- "inputs": {}, "fields": {"VARIABLE": ["my variable", "`jEk@4|i[#Fk?(8x)AV.-my variable"]}, "shadow": False, "topLevel": True
612
- },
613
- "data_addtolist": {
614
- "block_name": "add () to [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_addtolist",
615
- "functionality": "Appends an item to the end of a list.",
616
- "inputs": {"ITEM": [1, [10, "thing"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
617
- },
618
- "data_deleteoflist": {
619
- "block_name": "delete () of [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_deleteoflist",
620
- "functionality": "Removes an item from a list by its index or by selecting 'all' items.",
621
- "inputs": {"INDEX": [1, [7, "1"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
622
- },
623
- "data_deletealloflist": {
624
- "block_name": "delete all of [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_deletealloflist",
625
- "functionality": "Removes all items from a list.",
626
- "inputs": {}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
627
- },
628
- "data_insertatlist": {
629
- "block_name": "insert () at () of [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_insertatlist",
630
- "functionality": "Inserts an item at a specific position within a list.",
631
- "inputs": {"ITEM": [1, [10, "thing"]], "INDEX": [1, [7, "1"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
632
- },
633
- "data_replaceitemoflist": {
634
- "block_name": "replace item () of [my list v] with ()", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_replaceitemoflist",
635
- "functionality": "Replaces an item at a specific position in a list with a new value.",
636
- "inputs": {"INDEX": [1, [7, "1"]], "ITEM": [1, [10, "thing"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
637
- },
638
- "data_itemoflist": {
639
- "block_name": "(item (2) of [myList v])", "block_type": "Data", "block_shape": "Reporter Block", "op_code": "data_itemoflist",
640
- "functionality": "Reports the item located at a specific position in a list.",
641
- "inputs": {"INDEX": [1, [7, "1"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
642
- },
643
- "data_itemnumoflist": {
644
- "block_name": "(item # of [Dog] in [myList v])", "block_type": "Data", "block_shape": "Reporter Block", "op_code": "data_itemnumoflist",
645
- "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.",
646
- "inputs": {"ITEM": [1, [10, "thing"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
647
- },
648
- "data_lengthoflist": {
649
- "block_name": "(length of [myList v])", "block_type": "Data", "block_shape": "Reporter Block", "op_code": "data_lengthoflist",
650
- "functionality": "Provides the total number of items contained in a list.",
651
- "inputs": {}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
652
- },
653
- "data_listcontainsitem": {
654
- "block_name": "<[my list v] contains ()?>", "block_type": "Data", "block_shape": "Boolean Block", "op_code": "data_listcontainsitem",
655
- "functionality": "Checks if a list includes a specific item.",
656
- "inputs": {"ITEM": [1, [10, "thing"]]}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
657
- },
658
- "data_showlist": {
659
- "block_name": "show list [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_showlist",
660
- "functionality": "Makes a list's monitor visible on the stage.",
661
- "inputs": {}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
662
- },
663
- "data_hidelist": {
664
- "block_name": "hide list [my list v]", "block_type": "Data", "block_shape": "Stack Block", "op_code": "data_hidelist",
665
- "functionality": "Hides a list's monitor from the stage.",
666
- "inputs": {}, "fields": {"LIST": ["MY_LIST", "o6`kIhtT{xWH+rX(5d,A"]}, "shadow": False, "topLevel": True
667
- },
668
- "data_variable": { # This is a reporter block for a variable's value
669
- "block_name": "[variable v]", "block_type": "Data", "block_shape": "Reporter Block", "op_code": "data_variable",
670
- "functionality": "Provides the current value stored in a variable.",
671
- "inputs": {}, "fields": {"VARIABLE": ["my variable", None]}, "shadow": True, "topLevel": False
672
- },
673
-
674
- # event_block.json
675
- "event_whenflagclicked": {
676
- "block_name": "when green flag pressed", "block_type": "Events", "op_code": "event_whenflagclicked", "block_shape": "Hat Block",
677
- "functionality": "This Hat block initiates the script when the green flag is clicked, serving as the common starting point for most Scratch projects.",
678
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
679
- },
680
- "event_whenkeypressed": {
681
- "block_name": "when () key pressed", "block_type": "Events", "op_code": "event_whenkeypressed", "block_shape": "Hat Block",
682
- "functionality": "This Hat block initiates the script when a specified keyboard key is pressed.",
683
- "inputs": {}, "fields": {"KEY_OPTION": ["space", None]}, "shadow": False, "topLevel": True
684
- },
685
- "event_whenthisspriteclicked": {
686
- "block_name": "when this sprite clicked", "block_type": "Events", "op_code": "event_whenthisspriteclicked", "block_shape": "Hat Block",
687
- "functionality": "This Hat block starts the script when the sprite itself is clicked.",
688
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
689
- },
690
- "event_whenbackdropswitchesto": {
691
- "block_name": "when backdrop switches to ()", "block_type": "Events", "op_code": "event_whenbackdropswitchesto", "block_shape": "Hat Block",
692
- "functionality": "This Hat block triggers the script when the stage backdrop changes to a specified backdrop.",
693
- "inputs": {}, "fields": {"BACKDROP": ["backdrop1", None]}, "shadow": False, "topLevel": True
694
- },
695
- "event_whengreaterthan": {
696
- "block_name": "when () > ()", "block_type": "Events", "op_code": "event_whengreaterthan", "block_shape": "Hat Block",
697
- "functionality": "This Hat block starts the script when a certain value (e.g., loudness from a microphone, or the timer) exceeds a defined threshold.",
698
- "inputs": {"VALUE": [1, [4, "10"]]}, "fields": {"WHENGREATERTHANMENU": ["LOUDNESS", None]}, "shadow": False, "topLevel": True
699
- },
700
- "event_whenbroadcastreceived": {
701
- "block_name": "when I receive ()", "block_type": "Events", "op_code": "event_whenbroadcastreceived", "block_shape": "Hat Block",
702
- "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.",
703
- "inputs": {}, "fields": {"BROADCAST_OPTION": ["message1", "5O!nei;S$!c!=hCT}0:a"]}, "shadow": False, "topLevel": True
704
- },
705
- "event_broadcast": {
706
- "block_name": "broadcast ()", "block_type": "Events", "block_shape": "Stack Block", "op_code": "event_broadcast",
707
- "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.",
708
- "inputs": {"BROADCAST_INPUT": [1, [11, "message1", "5O!nei;S$!c!=hCT}0:a"]]}, "fields": {}, "shadow": False, "topLevel": True
709
- },
710
- "event_broadcastandwait": {
711
- "block_name": "broadcast () and wait", "block_type": "Events", "block_shape": "Stack Block", "op_code": "event_broadcastandwait",
712
- "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.",
713
- "inputs": {"BROADCAST_INPUT": [1, [11, "message1", "5O!nei;S$!c!=hCT}0:a"]]}, "fields": {}, "shadow": False, "topLevel": True
714
- },
715
-
716
- # looks_block.json
717
- "looks_sayforsecs": {
718
- "block_name": "say () for () seconds", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_sayforsecs",
719
- "functionality": "Displays a speech bubble containing specified text for a set duration.",
720
- "inputs": {"MESSAGE": [1, [10, "Hello!"]], "SECS": [1, [4, "2"]]}, "fields": {}, "shadow": False, "topLevel": True
721
- },
722
- "looks_say": {
723
- "block_name": "say ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_say",
724
- "functionality": "Displays a speech bubble with the specified text indefinitely until another 'say' or 'think' block is activated.",
725
- "inputs": {"MESSAGE": [1, [10, "Hello!"]]}, "fields": {}, "shadow": False, "topLevel": True
726
- },
727
- "looks_thinkforsecs": {
728
- "block_name": "think () for () seconds", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_thinkforsecs",
729
- "functionality": "Displays a thought bubble containing specified text for a set duration.",
730
- "inputs": {"MESSAGE": [1, [10, "Hmm..."]], "SECS": [1, [4, "2"]]}, "fields": {}, "shadow": False, "topLevel": True
731
- },
732
- "looks_think": {
733
- "block_name": "think ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_think",
734
- "functionality": "Displays a thought bubble with the specified text indefinitely until another 'say' or 'think' block is activated.",
735
- "inputs": {"MESSAGE": [1, [10, "Hmm..."]]}, "fields": {}, "shadow": False, "topLevel": True
736
- },
737
- "looks_switchcostumeto": {
738
- "block_name": "switch costume to ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_switchcostumeto",
739
- "functionality": "Alters the sprite's appearance to a designated costume.",
740
- "inputs": {"COSTUME": [1, "looks_costume"]}, "fields": {}, "shadow": False, "topLevel": True
741
- },
742
- "looks_costume": {
743
- "block_name": "costume menu", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_costume",
744
- "functionality": "Menu for switch costume to block.",
745
- "inputs": {}, "fields": {"COSTUME": ["costume1", None]}, "shadow": True, "topLevel": False
746
- },
747
- "looks_nextcostume": {
748
- "block_name": "next costume", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_nextcostume",
749
- "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.",
750
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
751
- },
752
- "looks_switchbackdropto": {
753
- "block_name": "switch backdrop to ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_switchbackdropto",
754
- "functionality": "Changes the stage's backdrop to a specified backdrop.",
755
- "inputs": {"BACKDROP": [1, "looks_backdrops"]}, "fields": {}, "shadow": False, "topLevel": True
756
- },
757
- "looks_backdrops": {
758
- "block_name": "backdrop menu", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_backdrops",
759
- "functionality": "Menu for switch backdrop to block.",
760
- "inputs": {}, "fields": {"BACKDROP": ["backdrop1", None]}, "shadow": True, "topLevel": False
761
- },
762
- "looks_switchbackdroptowait": {
763
- "block_name": "switch backdrop to () and wait", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_switchbackdroptowait",
764
- "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.",
765
- "inputs": {"BACKDROP": [1, "looks_backdrops"]}, "fields": {}, "shadow": False, "topLevel": True
766
- },
767
- "looks_nextbackdrop": {
768
- "block_name": "next backdrop", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_nextbackdrop",
769
- "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.",
770
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
771
- },
772
- "looks_changesizeby": {
773
- "block_name": "change size by ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_changesizeby",
774
- "functionality": "Changes the sprite's size by a specified percentage. Positive values make it larger, negative values make it smaller.",
775
- "inputs": {"CHANGE": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
776
- },
777
- "looks_setsizeto": {
778
- "block_name": "set size to () %", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_setsizeto",
779
- "functionality": "Sets the sprite's size to a specific percentage of its original size.",
780
- "inputs": {"SIZE": [1, [4, "100"]]}, "fields": {}, "shadow": False, "topLevel": True
781
- },
782
- "looks_changeeffectby": {
783
- "block_name": "change () effect by ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_changeeffectby",
784
- "functionality": "Changes a visual effect on the sprite by a specified amount (e.g., color, fisheye, whirl, pixelate, mosaic, brightness, ghost).",
785
- "inputs": {"CHANGE": [1, [4, "25"]]}, "fields": {"EFFECT": ["COLOR", None]}, "shadow": False, "topLevel": True
786
- },
787
- "looks_seteffectto": {
788
- "block_name": "set () effect to ()", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_seteffectto",
789
- "functionality": "Sets a visual effect on the sprite to a specific value.",
790
- "inputs": {"VALUE": [1, [4, "0"]]}, "fields": {"EFFECT": ["COLOR", None]}, "shadow": False, "topLevel": True
791
- },
792
- "looks_cleargraphiceffects": {
793
- "block_name": "clear graphic effects", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_cleargraphiceffects",
794
- "functionality": "Removes all visual effects applied to the sprite.",
795
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
796
- },
797
- "looks_show": {
798
- "block_name": "show", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_show",
799
- "functionality": "Makes the sprite visible on the stage.",
800
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
801
- },
802
- "looks_hide": {
803
- "block_name": "hide", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_hide",
804
- "functionality": "Makes the sprite invisible on the stage.",
805
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
806
- },
807
- "looks_gotofrontback": {
808
- "block_name": "go to () layer", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_gotofrontback",
809
- "functionality": "Moves the sprite to the front-most or back-most layer of other sprites on the stage.",
810
- "inputs": {}, "fields": {"FRONT_BACK": ["front", None]}, "shadow": False, "topLevel": True
811
- },
812
- "looks_goforwardbackwardlayers": {
813
- "block_name": "go () layers", "block_type": "Looks", "block_shape": "Stack Block", "op_code": "looks_goforwardbackwardlayers",
814
- "functionality": "Moves the sprite forward or backward a specified number of layers in relation to other sprites.",
815
- "inputs": {"NUM": [1, [7, "1"]]}, "fields": {"FORWARD_BACKWARD": ["forward", None]}, "shadow": False, "topLevel": True
816
- },
817
- "looks_costumenumbername": {
818
- "block_name": "(costume ())", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_costumenumbername",
819
- "functionality": "Reports the current costume's number or name.",
820
- "inputs": {}, "fields": {"NUMBER_NAME": ["number", None]}, "shadow": False, "topLevel": True
821
- },
822
- "looks_backdropnumbername": {
823
- "block_name": "(backdrop ())", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_backdropnumbername",
824
- "functionality": "Reports the current backdrop's number or name.",
825
- "inputs": {}, "fields": {"NUMBER_NAME": ["number", None]}, "shadow": False, "topLevel": True
826
- },
827
- "looks_size": {
828
- "block_name": "(size)", "block_type": "Looks", "block_shape": "Reporter Block", "op_code": "looks_size",
829
- "functionality": "Reports the current size of the sprite as a percentage.",
830
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
831
- },
832
-
833
- # operator_block.json
834
- "operator_add": {
835
- "block_name": "(() + ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_add",
836
- "functionality": "Adds two numerical values.",
837
- "inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
838
- },
839
- "operator_subtract": {
840
- "block_name": "(() - ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_subtract",
841
- "functionality": "Subtracts the second numerical value from the first.",
842
- "inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
843
- },
844
- "operator_multiply": {
845
- "block_name": "(() * ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_multiply",
846
- "functionality": "Multiplies two numerical values.",
847
- "inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
848
- },
849
- "operator_divide": {
850
- "block_name": "(() / ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_divide",
851
- "functionality": "Divides the first numerical value by the second.",
852
- "inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
853
- },
854
- "operator_random": {
855
- "block_name": "(pick random () to ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_random",
856
- "functionality": "Generates a random integer within a specified inclusive range.",
857
- "inputs": {"FROM": [1, [4, "1"]], "TO": [1, [4, "10"]]}, "fields": {}, "shadow": False, "topLevel": True
858
- },
859
- "operator_gt": {
860
- "block_name": "<() > ()>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_gt",
861
- "functionality": "Checks if the first value is greater than the second.",
862
- "inputs": {"OPERAND1": [1, [10, ""]], "OPERAND2": [1, [10, "50"]]}, "fields": {}, "shadow": False, "topLevel": True
863
- },
864
- "operator_lt": {
865
- "block_name": "<() < ()>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_lt",
866
- "functionality": "Checks if the first value is less than the second.",
867
- "inputs": {"OPERAND1": [1, [10, ""]], "OPERAND2": [1, [10, "50"]]}, "fields": {}, "shadow": False, "topLevel": True
868
- },
869
- "operator_equals": {
870
- "block_name": "<() = ()>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_equals",
871
- "functionality": "Checks if two values are equal.",
872
- "inputs": {"OPERAND1": [1, [10, ""]], "OPERAND2": [1, [10, "50"]]}, "fields": {}, "shadow": False, "topLevel": True
873
- },
874
- "operator_and": {
875
- "block_name": "<<> and <>>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_and",
876
- "functionality": "Returns 'true' if both provided Boolean conditions are 'true'.",
877
- "inputs": {"OPERAND1": [2, None], "OPERAND2": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
878
- },
879
- "operator_or": {
880
- "block_name": "<<> or <>>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_or",
881
- "functionality": "Returns 'true' if at least one of the provided Boolean conditions is 'true'.",
882
- "inputs": {"OPERAND1": [2, None], "OPERAND2": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
883
- },
884
- "operator_not": {
885
- "block_name": "<not <>>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_not",
886
- "functionality": "Returns 'true' if the provided Boolean condition is 'false', and 'false' if it is 'true'.",
887
- "inputs": {"OPERAND": [2, None]}, "fields": {}, "shadow": False, "topLevel": True
888
- },
889
- "operator_join": {
890
- "block_name": "(join ()())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_join",
891
- "functionality": "Concatenates two strings or values into a single string.",
892
- "inputs": {"STRING1": [1, [10, "apple "]], "STRING2": [1, [10, "banana"]]}, "fields": {}, "shadow": False, "topLevel": True
893
- },
894
- "operator_letterof": {
895
- "block_name": "letter () of ()", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_letterof",
896
- "functionality": "Reports the character at a specific numerical position within a string.",
897
- "inputs": {"LETTER": [1, [6, "1"]], "STRING": [1, [10, "apple"]]}, "fields": {}, "shadow": False, "topLevel": True
898
- },
899
- "operator_length": {
900
- "block_name": "(length of ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_length",
901
- "functionality": "Reports the total number of characters in a given string.",
902
- "inputs": {"STRING": [1, [10, "apple"]]}, "fields": {}, "shadow": False, "topLevel": True
903
- },
904
- "operator_contains": {
905
- "block_name": "<() contains ()?>", "block_type": "operator", "block_shape": "Boolean Block", "op_code": "operator_contains",
906
- "functionality": "Checks if one string contains another string.",
907
- "inputs": {"STRING1": [1, [10, "apple"]], "STRING2": [1, [10, "a"]]}, "fields": {}, "shadow": False, "topLevel": True
908
- },
909
- "operator_mod": {
910
- "block_name": "(() mod ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_mod",
911
- "functionality": "Reports the remainder when the first number is divided by the second.",
912
- "inputs": {"NUM1": [1, [4, ""]], "NUM2": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
913
- },
914
- "operator_round": {
915
- "block_name": "(round ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_round",
916
- "functionality": "Rounds a numerical value to the nearest integer.",
917
- "inputs": {"NUM": [1, [4, ""]]}, "fields": {}, "shadow": False, "topLevel": True
918
- },
919
- "operator_mathop": {
920
- "block_name": "(() of ())", "block_type": "operator", "block_shape": "Reporter Block", "op_code": "operator_mathop",
921
- "functionality": "Performs various mathematical functions (e.g., absolute value, square root, trigonometric functions).",
922
- "inputs": {"NUM": [1, [4, ""]]}, "fields": {"OPERATOR": ["abs", None]}, "shadow": False, "topLevel": True
923
- },
924
-
925
- # sensing_block.json
926
- "sensing_touchingobject": {
927
- "block_name": "<touching [edge v]?>", "block_type": "Sensing", "op_code": "sensing_touchingobject", "block_shape": "Boolean Block",
928
- "functionality": "Checks if its sprite is touching the mouse-pointer, edge, or another specified sprite.",
929
- "inputs": {"TOUCHINGOBJECTMENU": [1, "sensing_touchingobjectmenu"]}, "fields": {}, "shadow": False, "topLevel": True
930
- },
931
- "sensing_touchingobjectmenu": {
932
- "block_name": "touching object menu", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_touchingobjectmenu",
933
- "functionality": "Menu for touching object block.",
934
- "inputs": {}, "fields": {"TOUCHINGOBJECTMENU": ["_mouse_", None]}, "shadow": True, "topLevel": False
935
- },
936
- "sensing_touchingcolor": {
937
- "block_name": "<touching color ()?>", "block_type": "Sensing", "op_code": "sensing_touchingcolor", "block_shape": "Boolean Block",
938
- "functionality": "Checks whether its sprite is touching a specified color.",
939
- "inputs": {"COLOR": [1, [9, "#55b888"]]}, "fields": {}, "shadow": False, "topLevel": True
940
- },
941
- "sensing_coloristouchingcolor": {
942
- "block_name": "<color () is touching ()?>", "block_type": "Sensing", "op_code": "sensing_coloristouchingcolor", "block_shape": "Boolean Block",
943
- "functionality": "Checks whether a specific color on its sprite is touching another specified color on the stage or another sprite.",
944
- "inputs": {"COLOR1": [1, [9, "#d019f2"]], "COLOR2": [1, [9, "#2b0de3"]]}, "fields": {}, "shadow": False, "topLevel": True
945
- },
946
- "sensing_askandwait": {
947
- "block_name": "Ask () and Wait", "block_type": "Sensing", "block_shape": "Stack Block", "op_code": "sensing_askandwait",
948
- "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.",
949
- "inputs": {"QUESTION": [1, [10, "What's your name?"]]}, "fields": {}, "shadow": False, "topLevel": True
950
- },
951
- "sensing_answer": {
952
- "block_name": "(answer)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_answer",
953
- "functionality": "Holds the most recent text inputted using the 'Ask () and Wait' block.",
954
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
955
- },
956
- "sensing_keypressed": {
957
- "block_name": "<key () pressed?>", "block_type": "Sensing", "op_code": "sensing_keypressed", "block_shape": "Boolean Block",
958
- "functionality": "Checks if a specified keyboard key is currently being pressed.",
959
- "inputs": {"KEY_OPTION": [1, "sensing_keyoptions"]}, "fields": {}, "shadow": False, "topLevel": True
960
- },
961
- "sensing_keyoptions": {
962
- "block_name": "key options menu", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_keyoptions",
963
- "functionality": "Menu for key pressed block.",
964
- "inputs": {}, "fields": {"KEY_OPTION": ["space", None]}, "shadow": True, "topLevel": False
965
- },
966
- "sensing_mousedown": {
967
- "block_name": "<mouse down?>", "block_type": "Sensing", "op_code": "sensing_mousedown", "block_shape": "Boolean Block",
968
- "functionality": "Checks if the computer mouse's primary button is being clicked while the cursor is over the stage.",
969
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
970
- },
971
- "sensing_mousex": {
972
- "block_name": "(mouse x)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_mousex",
973
- "functionality": "Reports the mouse-pointer’s current X position on the stage.",
974
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
975
- },
976
- "sensing_mousey": {
977
- "block_name": "(mouse y)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_mousey",
978
- "functionality": "Reports the mouse-pointer’s current Y position on the stage.",
979
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
980
- },
981
- "sensing_setdragmode": {
982
- "block_name": "set drag mode [draggable v]", "block_type": "Sensing", "block_shape": "Stack Block", "op_code": "sensing_setdragmode",
983
- "functionality": "Sets whether the sprite can be dragged by the mouse on the stage.",
984
- "inputs": {}, "fields": {"DRAG_MODE": ["draggable", None]}, "shadow": False, "topLevel": True
985
- },
986
- "sensing_loudness": {
987
- "block_name": "(loudness)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_loudness",
988
- "functionality": "Reports the loudness of noise received by a microphone on a scale of 0 to 100.",
989
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
990
- },
991
- "sensing_timer": {
992
- "block_name": "(timer)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_timer",
993
- "functionality": "Reports the elapsed time since Scratch was launched or the timer was reset, increasing by 1 every second.",
994
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
995
- },
996
- "sensing_resettimer": {
997
- "block_name": "Reset Timer", "block_type": "Sensing", "block_shape": "Stack Block", "op_code": "sensing_resettimer",
998
- "functionality": "Sets the timer’s value back to 0.0.",
999
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
1000
- },
1001
- "sensing_of": {
1002
- "block_name": "(() of ())", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_of",
1003
- "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.",
1004
- "inputs": {"OBJECT": [1, "sensing_of_object_menu"]}, "fields": {"PROPERTY": ["backdrop #", None]}, "shadow": False, "topLevel": True
1005
- },
1006
- "sensing_of_object_menu": {
1007
- "block_name": "of object menu", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_of_object_menu",
1008
- "functionality": "Menu for of block.",
1009
- "inputs": {}, "fields": {"OBJECT": ["_stage_", None]}, "shadow": True, "topLevel": False
1010
- },
1011
- "sensing_current": {
1012
- "block_name": "(current ())", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_current",
1013
- "functionality": "Reports the current local year, month, date, day of the week, hour, minutes, or seconds.",
1014
- "inputs": {}, "fields": {"CURRENTMENU": ["YEAR", None]}, "shadow": False, "topLevel": True
1015
- },
1016
- "sensing_dayssince2000": {
1017
- "block_name": "(days since 2000)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_dayssince2000",
1018
- "functionality": "Reports the number of days (and fractions of a day) since 00:00:00 UTC on January 1, 2000.",
1019
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
1020
- },
1021
- "sensing_username": {
1022
- "block_name": "(username)", "block_type": "Sensing", "block_shape": "Reporter Block", "op_code": "sensing_username",
1023
- "functionality": "Reports the username of the user currently logged into Scratch. If no user is logged in, it reports nothing.",
1024
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
1025
- },
1026
-
1027
- # sound_block.json
1028
- "sound_playuntildone": {
1029
- "block_name": "play sound () until done", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_playuntildone",
1030
- "functionality": "Plays a specified sound and pauses the script's execution until the sound has completed.",
1031
- "inputs": {"SOUND_MENU": [1, "sound_sounds_menu"]}, "fields": {}, "shadow": False, "topLevel": True
1032
- },
1033
- "sound_sounds_menu": {
1034
- "block_name": "sound menu", "block_type": "Sound", "block_shape": "Reporter Block", "op_code": "sound_sounds_menu",
1035
- "functionality": "Menu for sound blocks.",
1036
- "inputs": {}, "fields": {"SOUND_MENU": ["Meow", None]}, "shadow": True, "topLevel": False
1037
- },
1038
- "sound_play": {
1039
- "block_name": "start sound ()", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_play",
1040
- "functionality": "Initiates playback of a specified sound without pausing the script, allowing other actions to proceed concurrently.",
1041
- "inputs": {"SOUND_MENU": [1, "sound_sounds_menu"]}, "fields": {}, "shadow": False, "topLevel": True
1042
- },
1043
- "sound_stopallsounds": {
1044
- "block_name": "stop all sounds", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_stopallsounds",
1045
- "functionality": "Stops all currently playing sounds.",
1046
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
1047
- },
1048
- "sound_changeeffectby": {
1049
- "block_name": "change () effect by ()", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_changeeffectby",
1050
- "functionality": "Changes the project's sound effect by a specified amount.",
1051
- "inputs": {"VALUE": [1, [4, "10"]]}, "fields": {"EFFECT": ["PITCH", None]}, "shadow": False, "topLevel": True
1052
- },
1053
- "sound_seteffectto": {
1054
- "block_name": "set () effect to ()", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_seteffectto",
1055
- "functionality": "Sets the sound effect to a specific value.",
1056
- "inputs": {"VALUE": [1, [4, "100"]]}, "fields": {"EFFECT": ["PITCH", None]}, "shadow": False, "topLevel": True
1057
- },
1058
- "sound_cleareffects": {
1059
- "block_name": "clear sound effects", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_cleareffects",
1060
- "functionality": "Removes all sound effects applied to the sprite.",
1061
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
1062
- },
1063
- "sound_changevolumeby": {
1064
- "block_name": "change volume by ()", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_changevolumeby",
1065
- "functionality": "Changes the project's sound volume by a specified amount.",
1066
- "inputs": {"VOLUME": [1, [4, "-10"]]}, "fields": {}, "shadow": False, "topLevel": True
1067
- },
1068
- "sound_setvolumeto": {
1069
- "block_name": "set volume to () %", "block_type": "Sound", "block_shape": "Stack Block", "op_code": "sound_setvolumeto",
1070
- "functionality": "Sets the sound volume to a specific percentage (0-100).",
1071
- "inputs": {"VOLUME": [1, [4, "100"]]}, "fields": {}, "shadow": False, "topLevel": True
1072
- },
1073
- "sound_volume": {
1074
- "block_name": "(volume)", "block_type": "Sound", "block_shape": "Reporter Block", "op_code": "sound_volume",
1075
- "functionality": "Reports the current volume level of the sprite.",
1076
- "inputs": {}, "fields": {}, "shadow": False, "topLevel": True
1077
- },
1078
- }
1079
-
1080
- # Example input with opcodes for the initial generation
1081
- initial_opcode_counts = [
1082
- {"opcode":"event_whenflagclicked","count":1},
1083
- {"opcode":"motion_gotoxy","count":1},
1084
- {"opcode":"motion_glidesecstoxy","count":1},
1085
- {"opcode":"motion_xposition","count":1},
1086
- {"opcode":"motion_setx","count":1},
1087
- {"opcode":"control_forever","count":1},
1088
- {"opcode":"control_if","count":1},
1089
- {"opcode":"control_stop","count":1},
1090
- {"opcode":"operator_lt","count":1},
1091
- {"opcode":"sensing_touchingobject","count":1}, # Changed from sensing_istouching
1092
- {"opcode":"sensing_touchingobjectmenu","count":1},
1093
- {"opcode":"event_broadcast","count":1},
1094
- {"opcode":"data_setvariableto","count":2},
1095
- {"opcode":"data_showvariable","count":2},
1096
- ]
1097
-
1098
- # Generate the initial blocks and get the opcode_occurrences
1099
- generated_output_json, initial_opcode_occurrences = generate_blocks_from_opcodes(initial_opcode_counts, all_block_definitions)
1100
-
1101
- # Pseudo-code to interpret
1102
- pseudo_code_input = """
1103
- when green flag clicked
1104
- go to x: (240) y: (-135)
1105
- set [score v] to (1)
1106
- set [speed v] to (1)
1107
- show variable [score v]
1108
- show variable [speed v]
1109
- forever
1110
- glide (2) seconds to x: (-240) y: (-135)
1111
- if <((x position)) < (-235)> then
1112
- set x to (240)
1113
- end
1114
- if <touching [Sprite1 v]?> then
1115
- broadcast [Game Over v]
1116
- stop [all v]
1117
- end
1118
- end
1119
- end
1120
- """
1121
-
1122
- # Interpret the pseudo-code and update the blocks, passing opcode_occurrences
1123
- final_generated_blocks = interpret_pseudo_code_and_update_blocks(generated_output_json, pseudo_code_input, all_block_definitions, initial_opcode_occurrences)
1124
-
1125
- print(initial_opcode_occurrences)
1126
-
1127
- #print(json.dumps(final_generated_blocks, indent=2))
1128
- # ```json
1129
- # {
1130
- # "event_whenflagclicked_1": {
1131
- # "block_name": "when green flag pressed",
1132
- # "block_type": "Events",
1133
- # "op_code": "event_whenflagclicked",
1134
- # "block_shape": "Hat Block",
1135
- # "functionality": "This Hat block initiates the script when the green flag is clicked, serving as the common starting point for most Scratch projects.",
1136
- # "inputs": {},
1137
- # "fields": {},
1138
- # "shadow": false,
1139
- # "topLevel": true,
1140
- # "parent": null,
1141
- # "next": "motion_gotoxy_1"
1142
- # },
1143
- # "motion_gotoxy_1": {
1144
- # "block_name": "go to x: () y: ()",
1145
- # "block_type": "Motion",
1146
- # "op_code": "motion_gotoxy",
1147
- # "functionality": "Moves the sprite to the specified X and Y coordinates on the stage.",
1148
- # "inputs": {
1149
- # "X": [
1150
- # 4,
1151
- # "240"
1152
- # ],
1153
- # "Y": [
1154
- # 4,
1155
- # "-135"
1156
- # ]
1157
- # },
1158
- # "fields": {},
1159
- # "shadow": false,
1160
- # "topLevel": false,
1161
- # "parent": null,
1162
- # "next": "data_setvariableto_1"
1163
- # },
1164
- # "motion_glidesecstoxy_1": {
1165
- # "block_name": "glide () secs to x: () y: ()",
1166
- # "block_type": "Motion",
1167
- # "op_code": "motion_glidesecstoxy",
1168
- # "functionality": "Glides the sprite smoothly to the specified X and Y coordinates over a given number of seconds.",
1169
- # "inputs": {
1170
- # "SECS": [
1171
- # 4,
1172
- # "2"
1173
- # ],
1174
- # "X": [
1175
- # 4,
1176
- # "-240"
1177
- # ],
1178
- # "Y": [
1179
- # 4,
1180
- # "-135"
1181
- # ]
1182
- # },
1183
- # "fields": {},
1184
- # "shadow": false,
1185
- # "topLevel": false,
1186
- # "parent": "control_forever_1",
1187
- # "next": "control_if_1"
1188
- # },
1189
- # "motion_xposition_1": {
1190
- # "block_name": "(x position)",
1191
- # "block_type": "Motion",
1192
- # "op_code": "motion_xposition",
1193
- # "functionality": "Reports the current X-coordinate of the sprite.[NOTE: not used in stage/backdrops]",
1194
- # "inputs": {},
1195
- # "fields": {},
1196
- # "shadow": true,
1197
- # "topLevel": false,
1198
- # "parent": "operator_lt_1",
1199
- # "next": null
1200
- # },
1201
- # "motion_setx_1": {
1202
- # "block_name": "set x to ()",
1203
- # "block_type": "Motion",
1204
- # "op_code": "motion_setx",
1205
- # "functionality": "Sets the sprite's X-coordinate to a specific value, placing it at a precise horizontal position.",
1206
- # "inputs": {
1207
- # "X": [
1208
- # 4,
1209
- # "240"
1210
- # ]
1211
- # },
1212
- # "fields": {},
1213
- # "shadow": false,
1214
- # "topLevel": false,
1215
- # "parent": "control_if_1",
1216
- # "next": null
1217
- # },
1218
- # "control_forever_1": {
1219
- # "block_name": "forever",
1220
- # "block_type": "Control",
1221
- # "op_code": "control_forever",
1222
- # "functionality": "Continuously runs the blocks inside it.",
1223
- # "inputs": {
1224
- # "SUBSTACK": [
1225
- # 2,
1226
- # "motion_glidesecstoxy_1"
1227
- # ]
1228
- # },
1229
- # "fields": {},
1230
- # "shadow": false,
1231
- # "topLevel": false,
1232
- # "parent": null,
1233
- # "next": null
1234
- # },
1235
- # "control_if_1": {
1236
- # "block_name": "if <> then",
1237
- # "block_type": "Control",
1238
- # "op_code": "control_if",
1239
- # "functionality": "Executes the blocks inside it only if the specified boolean condition is true. [NOTE: it takes boolean blocks as input]",
1240
- # "inputs": {
1241
- # "CONDITION": [
1242
- # 2,
1243
- # "operator_lt_1"
1244
- # ],
1245
- # "SUBSTACK": [
1246
- # 2,
1247
- # "motion_setx_1"
1248
- # ]
1249
- # },
1250
- # "fields": {},
1251
- # "shadow": false,
1252
- # "topLevel": false,
1253
- # "parent": "control_forever_1",
1254
- # "next": "control_if_2"
1255
- # },
1256
- # "control_stop_1": {
1257
- # "block_name": "stop [v]",
1258
- # "block_type": "Control",
1259
- # "op_code": "control_stop",
1260
- # "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.",
1261
- # "inputs": {},
1262
- # "fields": {
1263
- # "STOP_OPTION": [
1264
- # "all",
1265
- # null
1266
- # ]
1267
- # },
1268
- # "shadow": false,
1269
- # "topLevel": false,
1270
- # "parent": "control_if_2",
1271
- # "mutation": {
1272
- # "tagName": "mutation",
1273
- # "children": [],
1274
- # "hasnext": "false"
1275
- # },
1276
- # "next": null
1277
- # },
1278
- # "operator_lt_1": {
1279
- # "block_name": "<() < ()>",
1280
- # "block_type": "operator",
1281
- # "op_code": "operator_lt",
1282
- # "functionality": "Checks if the first value is less than the second.",
1283
- # "inputs": {
1284
- # "OPERAND1": [
1285
- # 1,
1286
- # "motion_xposition_1"
1287
- # ],
1288
- # "OPERAND2": [
1289
- # 4,
1290
- # "-235"
1291
- # ]
1292
- # },
1293
- # "fields": {},
1294
- # "shadow": true,
1295
- # "topLevel": false,
1296
- # "parent": "control_if_1",
1297
- # "next": null
1298
- # },
1299
- # "sensing_touchingobject_1": {
1300
- # "block_name": "<touching [edge v]?>",
1301
- # "block_type": "Sensing",
1302
- # "op_code": "sensing_touchingobject",
1303
- # "functionality": "Checks if its sprite is touching the mouse-pointer, edge, or another specified sprite.",
1304
- # "inputs": {
1305
- # "TOUCHINGOBJECTMENU": [
1306
- # 1,
1307
- # "sensing_touchingobjectmenu_1"
1308
- # ]
1309
- # },
1310
- # "fields": {},
1311
- # "shadow": true,
1312
- # "topLevel": false,
1313
- # "parent": "control_if_2",
1314
- # "next": null
1315
- # },
1316
- # "sensing_touchingobjectmenu_1": {
1317
- # "block_name": "touching object menu",
1318
- # "block_type": "Sensing",
1319
- # "op_code": "sensing_touchingobjectmenu",
1320
- # "functionality": "Menu for touching object block.",
1321
- # "inputs": {},
1322
- # "fields": {
1323
- # "TOUCHINGOBJECTMENU": [
1324
- # "Sprite1",
1325
- # null
1326
- # ]
1327
- # },
1328
- # "shadow": true,
1329
- # "topLevel": false,
1330
- # "parent": "sensing_touchingobject_1",
1331
- # "next": null
1332
- # },
1333
- # "event_broadcast_1": {
1334
- # "block_name": "broadcast ()",
1335
- # "block_type": "Events",
1336
- # "op_code": "event_broadcast",
1337
- # "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.",
1338
- # "inputs": {
1339
- # "BROADCAST_INPUT": [
1340
- # 10,
1341
- # "Game Over"
1342
- # ]
1343
- # },
1344
- # "fields": {},
1345
- # "shadow": false,
1346
- # "topLevel": false,
1347
- # "parent": "control_if_2",
1348
- # "next": "control_stop_1"
1349
- # },
1350
- # "data_setvariableto_1": {
1351
- # "block_name": "set [my variable v] to ()",
1352
- # "block_type": "Data",
1353
- # "op_code": "data_setvariableto",
1354
- # "functionality": "Assigns a specific value (number, string, or boolean) to a variable.",
1355
- # "inputs": {
1356
- # "VALUE": [
1357
- # 4,
1358
- # "1"
1359
- # ]
1360
- # },
1361
- # "fields": {
1362
- # "VARIABLE": [
1363
- # "score",
1364
- # "`var_score"
1365
- # ]
1366
- # },
1367
- # "shadow": false,
1368
- # "topLevel": false,
1369
- # "parent": null,
1370
- # "next": "data_setvariableto_2"
1371
- # },
1372
- # "data_setvariableto_2": {
1373
- # "block_name": "set [my variable v] to ()",
1374
- # "block_type": "Data",
1375
- # "op_code": "data_setvariableto",
1376
- # "functionality": "Assigns a specific value (number, string, or boolean) to a variable.",
1377
- # "inputs": {
1378
- # "VALUE": [
1379
- # 4,
1380
- # "1"
1381
- # ]
1382
- # },
1383
- # "fields": {
1384
- # "VARIABLE": [
1385
- # "speed",
1386
- # "`var_speed"
1387
- # ]
1388
- # },
1389
- # "shadow": false,
1390
- # "topLevel": false,
1391
- # "parent": null,
1392
- # "next": "data_showvariable_1"
1393
- # },
1394
- # "data_showvariable_1": {
1395
- # "block_name": "show variable [my variable v]",
1396
- # "block_type": "Data",
1397
- # "op_code": "data_showvariable",
1398
- # "functionality": "Makes a variable's monitor visible on the stage.",
1399
- # "inputs": {},
1400
- # "fields": {
1401
- # "VARIABLE": [
1402
- # "score",
1403
- # "`var_score"
1404
- # ]
1405
- # },
1406
- # "shadow": false,
1407
- # "topLevel": false,
1408
- # "parent": null,
1409
- # "next": "data_showvariable_2"
1410
- # },
1411
- # "data_showvariable_2": {
1412
- # "block_name": "show variable [my variable v]",
1413
- # "block_type": "Data",
1414
- # "op_code": "data_showvariable",
1415
- # "functionality": "Makes a variable's monitor visible on the stage.",
1416
- # "inputs": {},
1417
- # "fields": {
1418
- # "VARIABLE": [
1419
- # "speed",
1420
- # "`var_speed"
1421
- # ]
1422
- # },
1423
- # "shadow": false,
1424
- # "topLevel": false,
1425
- # "parent": null,
1426
- # "next": "control_forever_1"
1427
- # },
1428
- # "control_if_2": {
1429
- # "block_name": "if <> then",
1430
- # "block_type": "Control",
1431
- # "op_code": "control_if",
1432
- # "functionality": "Executes the blocks inside it only if the specified boolean condition is true. [NOTE: it takes boolean blocks as input]",
1433
- # "inputs": {
1434
- # "CONDITION": [
1435
- # 2,
1436
- # "sensing_touchingobject_1"
1437
- # ],
1438
- # "SUBSTACK": [
1439
- # 2,
1440
- # "event_broadcast_1"
1441
- # ]
1442
- # },
1443
- # "fields": {},
1444
- # "shadow": false,
1445
- # "topLevel": false,
1446
- # "parent": "control_forever_1",
1447
- # "next": null
1448
- # }
1449
- # }