Yet again I have another Pygame question, and I apologize in advance if my question is very unclear.
After tearing a few games apart from the website, I saw that the games use something like "chapters" or "scenes", where there is a class of something like the "Main Menu" loop, or like a "Level1" loop, etc.
So what I found was that the main file, the .py file I open to run the game initially, would serve as the mother loop that collects returned results from these objects as they close to open up the next object when the iteration reads it.
For example, the game runs and automatically opens up a title/mainmenu loop object, and when a selection is made, the loop closes out, returning some form of data like a string or number back to the mother loop, and the next iteration of the mother loop would read that returned number, and open up the proper loop object, such as a high scores list or the first level.
My question is:
How do I get to communicate with the game's global constants while inside of an object's loop that would be running the section of the game I'm playing?
Like if I'm in the main menu, how would I get my selection to return the selection I want to open up the next loop object. Or while I'm in the game in a loop playing the level, how would I be able to get the camera object or the random.seed variable I had set up already in the main file so I don't have to create more instances inside the class?
The only way I got past this was to put everything I want inside the class as parameters when I call the Start() function to get its loop running. Unless I'm wrong, I would think that's pretty unnecessary, especially if I opened the game through the main file, where I should be able to communicate between everything easily.
Thanks in advance. btw you are all great help
After tearing a few games apart from the website, I saw that the games use something like "chapters" or "scenes", where there is a class of something like the "Main Menu" loop, or like a "Level1" loop, etc.
So what I found was that the main file, the .py file I open to run the game initially, would serve as the mother loop that collects returned results from these objects as they close to open up the next object when the iteration reads it.
For example, the game runs and automatically opens up a title/mainmenu loop object, and when a selection is made, the loop closes out, returning some form of data like a string or number back to the mother loop, and the next iteration of the mother loop would read that returned number, and open up the proper loop object, such as a high scores list or the first level.
My question is:
How do I get to communicate with the game's global constants while inside of an object's loop that would be running the section of the game I'm playing?
Like if I'm in the main menu, how would I get my selection to return the selection I want to open up the next loop object. Or while I'm in the game in a loop playing the level, how would I be able to get the camera object or the random.seed variable I had set up already in the main file so I don't have to create more instances inside the class?
The only way I got past this was to put everything I want inside the class as parameters when I call the Start() function to get its loop running. Unless I'm wrong, I would think that's pretty unnecessary, especially if I opened the game through the main file, where I should be able to communicate between everything easily.
Thanks in advance. btw you are all great help
