Skip to content

Commit 9659baa

Browse files
committed
Add "if ... then" block support
1 parent ac8c423 commit 9659baa

File tree

4 files changed

+5
-11
lines changed

4 files changed

+5
-11
lines changed

block.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def evaluateBlockValue(self, eventContainer=eventContainer.EventContainer):
8888
return newY
8989
elif self.opcode == "sensing_keypressed": # key pressed?
9090
return KEY_MAPPING[self.getMenuValue("key_option")] in eventContainer.keys
91-
elif self.opcode == "operators_not": # not <>
92-
return not self.evaluateBlockValue(self.getBlockInputValue("operand"))
91+
elif self.opcode == "operator_not": # not <>
92+
return not self.target.blocks[self.getBlockInputValue("operand")].evaluateBlockValue(eventContainer)
9393

9494
# Returns block input value
9595
def getBlockInputValue(self, inputId):

config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
# pygame X.Y.Z (SDL X.Y.Z, Python 3.Y.Z)
4848
# Hello from the pygame community. https://www.pygame.org/contribute.html"
4949
# message.
50-
5150
pygameWelcomeMessage: bool = True
5251

5352
# Enable Scratch Addons debugger logs

projects/NotKeyPressed.sb3

40.8 KB
Binary file not shown.

scratch.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,16 @@ def execute(block, s, events=eventContainer.EventContainer()):
367367
return nextBlock
368368

369369
elif opcode == "control_if": # if <> then {...}
370-
print("entered if", block.blockID)
371370
if block.target.blocks[inputs["CONDITION"][1]].evaluateBlockValue(events):
372371
# If there are blocks, get them
373372
if inputs["SUBSTACK"][1]:
374-
print("Running if substack")
375373
# No blocks will be flagged as ran inside a forever loop
376374
for b in block.substack:
377375
s.target.blocks[b].blockRan = False
378376
nextBlock = s.target.blocks[inputs["SUBSTACK"][1]]
379377
nb = s.target.blocks[inputs["SUBSTACK"][1]]
380378
block.substack.add(nb.blockID)
381-
while nb.next and nb.next != block.blockID:
379+
while nb.next and nb.next not in block.substack:
382380
nb.blockRan = False
383381
nb.waiting = False
384382
nb.timeDelay = 0
@@ -387,13 +385,10 @@ def execute(block, s, events=eventContainer.EventContainer()):
387385
block.substack.add(nb.blockID)
388386
nb.next = block.next
389387
block.blockRan = True
390-
print(nextBlock.blockID)
391388
return nextBlock
392-
print("No substack")
393389
block.blockRan = True
394390
# TODO why does it hang???
395391
else:
396-
print("condition is false, leaving")
397392
block.blockRan = True
398393
return s.target.blocks[block.next]
399394

@@ -460,9 +455,9 @@ def execute(block, s, events=eventContainer.EventContainer()):
460455
if block.proccode == "​​log​​ %s": # Scratch Addons log ()
461456
print("[", datetime.now().strftime("%H:%M:%S:%f"), "]", _("project-log"), block.getCustomInputValue(0), file=sys.stderr)
462457
elif block.proccode == "​​warn​​ %s": # Scratch Addons warn ()
463-
print(_("project-warn"), block.getCustomInputValue(0), file=sys.stderr)
458+
print("[", datetime.now().strftime("%H:%M:%S:%f"), "]", _("project-warn"), block.getCustomInputValue(0), file=sys.stderr)
464459
elif block.proccode == "​​error​​ %s": # Scratch Addons error ()
465-
print(_("project-error"), block.getCustomInputValue(0), file=sys.stderr)
460+
print("[", datetime.now().strftime("%H:%M:%S:%f"), "]", _("project-error"), block.getCustomInputValue(0), file=sys.stderr)
466461

467462
else:
468463
print(_("unknown-opcode"), opcode)

0 commit comments

Comments
 (0)