After a bit of digging, I found the issue. It has to do with the way imported variables are stored and updated. What I would guess is happening, is that the variable is just a number, so it is stored as a “constant”, which means the only way to change it is to completely reassign the value. So when you change the variable in
game_logic.py it replaces the old one with a new number and the one used in
main.py stays the same. (that wasn’t a very good explanation but I’m not sure how to explain it really)
Example of the problem:
from otherfile import my_var, changeMyVar, getMyVar
my_var = 10
my_var = x
Now if you run main.py, the output should look like this.
You can see that the variable used in
main.py doesn’t update, and therefore has the wrong value.
To solve this problem, just create a getter function inside of
game_logic.py that returns the scores as they should be.
add to game_logic.py
return user_score, computer_score
use in main.py
user_score, computer_score = get_scores()
One other thing I would recommend is instead of doing
from game_logic import *, only import what you will actually use, like this
from game_logic import game_logic, get_scores and then inside of your loop you call this to get the scores
user_score, computer_score = get_scores().
There are other ways to do it, but if the scores are just global variables that are just numbers then this is how you should do it.