#πŸ”’ event loop problems

6 messages Β· Page 1 of 1 (latest)

zinc sluice
#

having problems with my pygame event loop. it gets to the event handling but it cant seem to cope with checking the event type without hanging and crashing.

import pygame
import asyncio
import threading

pygame.init()
pygame.font.init() # just in case :3
# jfont = pygame.font.Font("VCR_OSD_MONO_1.001.ttf", 14)
screenSurface = pygame.display.set_mode((400,400))
clock = pygame.time.Clock()

gameState = "initing"
songname = ""
accuracy = 0
statesToTitleDict = {
"initing":"loading...",
"menu":"Menu",
"playing":"In Song: %s, accuracy %.1f%%",
"closing":"shutting down...",
}

def textSurfaceFabricator(text, color):
    return jfont.render(text,False,color)

async def titleUpdater():
    while gameState != "closing":
        if gameState != "playing":
            pygame.display.set_caption(statesToTitleDict[gameState])
        else:
            pygame.display.set_caption(statesToTitleDict[gameState] % (songname, accuracy))
    pygame.display.set_caption(statesToTitleDict["closing"])

def titleUpdaterInit():
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    asyncio.ensure_future(titleUpdater())
    loop.run_forever()

titupdathread = threading.Thread(target=titleUpdaterInit)
titupdathread.start()

while gameState != "closing":
    print("loop")
    for event in pygame.event.get():
        print(event)
        if event.type == pygame.QUIT:
            gameState = "closing"
            pygame.quit()
        else:
            print(event)
            pass
    print("after event handling")

    clock.tick(60)
obsidian pecanBOT
#

@zinc sluice

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

zinc sluice
#

it hangs on checking the event type

#

scroll up

obsidian pecanBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.