Skip to content

Commit 71a60c6

Browse files
committed
Key delay is not working
1 parent 74859ad commit 71a60c6

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
# Key delay
6565
# Set the delay before key events start repeating. (in milliseconds)
66-
keyDelay: int = 250
66+
keyDelay: int = 5000
6767

6868
# Screen width/height
6969
# Stage size. You can change that, but most projects won't work with it.

main.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def buttonbox(self):
240240
keyEventContainer = eventContainer.EventContainer()
241241

242242
# Mainloop
243+
counterValue = 0
243244
while projectRunning:
244245
# Process Pygame events
245246
for event in pygame.event.get():
@@ -254,7 +255,6 @@ def buttonbox(self):
254255
if event.type == pygame.KEYDOWN:
255256
keyEventContainer.keyEvents.add(event.key)
256257
print("new key event", time.time_ns())
257-
print(keyEventContainer.keyEvents, "after populating in main.py")
258258
keysRaw = pygame.key.get_pressed()
259259
keyEventContainer.keys = set(k for k in scratch.KEY_MAPPING.values() if keysRaw[k])
260260

@@ -307,14 +307,13 @@ def buttonbox(self):
307307
print(redrawMessage)
308308

309309
display.fill((255, 255, 255))
310-
if toExecute:
311-
for block in toExecute:
312-
pass
313310
if not isPaused:
311+
print("Starting frame at", time.time_ns())
314312
for e in eventHandlers:
315313
# TODO why does it run so many times???
316-
print("running", e.blockID)
317314
if e.opcode == "event_whenkeypressed" and keyEventContainer.keyEvents and not e.blockRan:
315+
print("running", e.blockID)
316+
318317
e.blockRan = True
319318
nextBlock = scratch.execute(e, e.target.sprite, keyEventContainer)
320319
if nextBlock and isinstance(nextBlock, list):
@@ -344,6 +343,8 @@ def buttonbox(self):
344343
block.executionTime, block.timeDelay = 0, 0
345344
if not block.blockRan and not block.opcode.startswith("event"): # TODO add broadcast blocks
346345
nextBlock = scratch.execute(block, block.target.sprite, keyEventContainer)
346+
if block.opcode == "looks_nextcostume":
347+
counterValue += 1
347348
if not block.next \
348349
and block.top \
349350
and block.top.opcode.startswith("event") \
@@ -368,6 +369,9 @@ def buttonbox(self):
368369
allSprites.update()
369370
else:
370371
display.blit(paused, (WIDTH // 2 - pausedWidth // 2, WIDTH // 2 - pausedHeight // 2))
372+
373+
counter = font.render(str(counterValue), True, (0, 0, 128))
374+
display.blit(counter, (WIDTH // 2 - pausedWidth // 2, WIDTH // 2 - pausedHeight // 2))
371375
pygame.display.flip()
372376
mainWindow.update()
373377
doScreenRefresh = False

scratch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def execute(block, s, events=eventContainer.EventContainer()):
225225
pass
226226

227227
elif opcode == "event_whenkeypressed":
228-
print(time.time_ns())
228+
print(time.time_ns(), "in whenkeypressed")
229229

230230
# print("Handling key event")
231231
# if not block.waiting:
@@ -263,7 +263,7 @@ def execute(block, s, events=eventContainer.EventContainer()):
263263
nb.blockRan = False
264264
nextBlock = s.target.blocks[block.next]
265265
return nextBlock
266-
elif KEY_MAPPING[key] in keyEvents and KEY_MAPPING[key] in keys and block.next: # when key [. . . v] pressed
266+
elif KEY_MAPPING[key] in keyEvents and block.next: # when key [. . . v] pressed
267267
print(keyEvents, "received in execute()")
268268
if key == "left arrow":
269269
keyName = _("key-left")

0 commit comments

Comments
 (0)