Home > database >  Running multiple loops whilst still listening to key inputs
Running multiple loops whilst still listening to key inputs

Time:09-15

I am working on a game driver but I can't get multiple loops to work together, I've tried using Threading and Multiprocessing but nothing seems to be working.

import turtle
from time import sleep
from functools import partial
game_active = True
render_speed = 0.01
driver_speed = 0.1


def prep_assets():
    print('asset WIP')


def game_render():
    while game_active:
        print('render WIP')
        sleep(render_speed)


def game_driver():
    while game_active:
        print('driver WIP')
        sleep(driver_speed)


def update_data(key):
    print(f'{key} wip')


prep_assets()
game_driver()
game_render()
turtle.onkey(partial(update_data, 'w'), 'w')
turtle.onkey(partial(update_data, 'a'), 'a')
turtle.onkey(partial(update_data, 's'), 's')
turtle.onkey(partial(update_data, 'd'), 'd')
turtle.onkey(partial(update_data, 'q'), 'q')
turtle.onkey(partial(update_data, 'e'), 'e')
turtle.listen()
turtle.mainloop()

CodePudding user response:

can u explain why Threading and Multiprocessing but nothing seems to be working.

 Thread(target = game_render).start()
    Thread(target = game_driver).start()
  • Related