0
\$\begingroup\$

I'm making a real-time risk-like game in Python. Players can move armies from one region to another. I want army movement to take time proportional to the distance between the two regions, therefore I need to keep a new timer every time an army moves from one region to another (until the army arrives).

I've thought of 2 ways to do this:

One way is to have a list of moving troops and do a for loop through this list every iteration of the main server loop to check if the time is up for each unit.

Another way is to create a new thread for each moving troop and have the run() method of the thread continuously check whether the time is up yet for the unit.

Which way is better?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Handle it in the main update loop if you can.

The first rule of multithreading is: Don't use multithreading unless you have to. "X and Y should happen simultaneously from the perspective of the user" is not an appropriate reason. You can handle that much better with an update-loop. The only reasons to ever use threads are performance and response time. The reason is that multithreading makes your program much harder to debug and that it introduces extremely difficult to reproduce problems due to thread timing ("race conditions").

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .