Ask coding questions

← Back to all posts
Is there a way to run two pieces of code at once in python?
Zackyd00 (0)

So I want to create an achievement system for something im making, but want it to update as the is running. Is there a way to do this?

Answered by Coder100 (18922) [earned 5 cycles]
View Answer
Coder100 (18922)

threading is what you want!

from threading import Thread

def func1():
  # your achievement code

def func2():
  # your normal game code

t1 = Thread(target = func1)
t2 = Thread(target = func2)

robowolf (550)

Try threading. Here's an example. How it works is essentially you run a function along with you other code.