MasterMind Game & Global Variables

(Ben) #1

-I was working on Global Variables in Blender.The best way I found, was to write a python script where to initiate all Global Variables.Then import it as module and use the variables in the form:


-Then their value can be changed in this way:

ModuleName.dict[“variable”] = newvalue

-In this way every script can have common variables which can be changed(in realtime) in any script and can be read by all other scripts without sending messagges,adding properties with the same name or connecting different object bricks.Distributing .blend files this module must be in the python path,but distributing executables it may be where the executable is.

-To test this I made a game.It is MasterMind(I think anyone knows it), a 2D simple game.In the zip file there are two files:Mastermind.blend(with which you know what to do) and ,which must be in the Python path or Blender folder otherwise the game doesn’t work.In the Blender 2.25 it needs to be in full screen,while in 2.23 it works in windows too.Link:

Thanks Ben

(OTO) #2

Hello Ben

Very, very nice!!
If i’ve followed my parents advices and go to school instead
of playing football, maybe now i could do some code :slight_smile:

But i’ll study yours
Thank you to share

(lizard809) #3

for global variables i just import GameLogic

how i change the value is:

this i think works better because you dont have to have an extra file since GameLogic exists within blender

(Yamyam) #4

Nice work. This is a good old tabletype game. I like it! :slight_smile: