Hello, I’m a new guy who just joined the forums a while back, have to work on a 3D game project with my friends, so I’ll most likely be popping by often…
The one thing I constantly have problems with at the moment, however, is the issue of “referencing”…
Lets say, you create an object Crate with the class of Crate. Is there any way that in the Crate class code, I can get the value of something from the World, or another object from another class?
myVariable = myValue
class myClass():
global myVariable
print myVariable
you could create another script globals.py, for instance, and type in all the world variables, to access them you type in your main script or in the script you want to print, change or use that global variables:
import globals
class myClass():
print globals.myVariable
EDIT: myVariable has to exist in the globals.py script
Yeah I think passing the instance of the world class would definitely be the best way here but I’m pretty sure it’s done like this
class Pie (DirectObject):
def __init__( self,w)
#note that I used w intead of world to avoid any issues with names
self.world = w
print self.world.wantpie