[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] setting + modifying a variable for use across the entire application



If your project (game I am assuming) is written in an OOP way then you
could just read in the settings/path in your main class and then pass
on a reference to that main class as an argument when ever you
instantiate a new object.


On Fri, Dec 2, 2011 at 10:15 AM, Sean Wolfe <ether.joe@xxxxxxxxx> wrote:
> Hey everybody,
>
> Upon initialization I'd like to set an assets path, which will be
> different depending on platform. I'd like to set it one time upon
> startup, and then have every module import it automatically with the
> changed value. However since modules are loaded once and persisted in
> their original state, I can't get the new value in the new module,
> even if I reload(settings) .
>
> The best option I can think of is actually creating a new module as a
> new file, then importing that new module in every subsequent piece
> that needs it. But I was hoping to do something a little more elegant
> than that. Do we have any sort of application-level variables which
> are muteable? Like an application-level memory space?
>
>
> ----------
> main.py:
> import settings
>
> if android:
> Â Âsettings.assets = './assets'
> else:
> Â Âsettings.assets = 'c:/my/sources/in/development/bla/bla'
>
>
> then in a future module something like this:
>
> ----------
> gameloop.py:
> import settings
>
> ASSETS_DIRECTORY = settings.assets
> player_img = pygame.image.load(ASSETS_DIRECTORY + 'player.png')
>
>
>
>
> --
> A musician must make music, an artist must paint, a poet must write,
> if he is to be ultimately at peace with himself.
> - Abraham Maslow
>



-- 
Ryan Hope, M.S.
CogWorks Lab
Department of Cognitive Science
Rensselaer Polytechnic Institute