keeping the same variables for another scene?

on the main menu for my game, you can change the settings and one of those is mouse sensitivity. So there’s a integer property for sensitivity and you can change it. I need a way to transfer the value into the other scene. Anyway I could do that?

I use GameLogic variables for things like that. You could setup a dictionary of settings and reference that. Pop it into a startup script on the splash scene and it’ll always be available.

E.g.


GameLogic.settings = {
"mouseSensitivity" : 0.01,
"movementSpeed" : 4.0
}

You can also check if the variable exists before redefining it, so you don’t reset your changes.

E.g.

if not hasattr(GameLogic, "settings"):
   GameLogic.settings = {
   "mouseSensitivity" : 0.01,
   "movementSpeed" : 4.0
   }

Thanks! trying it now

You can store this information in any module:

MySettings.py:


mouseSensitivity = 0.01,
movementSpeed = 4.0

you can read the values:


import MySettings
mouseSensitivity = MySettings.mouseSensitivity 
movementSpeed = MySettings.movementSpeed 

and change


import MySettings
MySettings.mouseSensitivity = 0.05
MySettings.movementSpeed = 10.0

The module will be creates with the first import and lives as long as the game lives (except you unload it explicitly).

Yeah, I didn’t know about the ability to use other modules, but it works, and it works well. You could, for example, store map data in a Map.py file (it obviously has to exist beforehand), or put player information in the Player.py file. It’s really useful. The power of Python strikes again. :cool:

Thanks guys! Working great now! And I learned about the power of the hasattr() function.

Haha Solarlune ;D