Okay, I'm trying to get my head round modules here. Kinda embarrassing.
So here is a module from a program I am writing:
- Code: Select all
file = open(lvl)
game_progress = file.read()
print("Game loaded at level " + str(game_progress) + "!")
The part I am struggling at is variables. I want to use 'game_progress' at other points in the program, however it doesn't carry over the whole program, as it's local(?).
I tried making it global by adding 'global game_progress' at the start of modules that used it, however, this had it's problems, and I have heard global variables are bad practice.
I know the brackets at 'def load_game():' can help with this but I don't quite know how. Do I put game_progress in there? No idea!
Sorry for my vague knowledge of python, I'm a beginner, and I've been doing well, but now I've started using modules I need to learn more about them.
Thanks for the help!