Sure, but you can do similar with a “common” file–and that provides a means of access to other things that you might often use, too.
Like so:
class Common
game = None
@staticmethod
def someCommonOperation(whateverDataItUses):
# Logic here
The main program then sets these things as appropriate:
from direct.showbase.ShowBase import ShowBase
from Common import Common
class Game(ShowBase):
def __init__(self):
ShowBase.__init__(self)
Common.game = self
self.player = player
Which can then likewise be used as called for–and gives access to more than just one method:
from Common import Common
class SomeClass():
def __init__(self):
self.model = Common.game.loader.loadModel("aModelFile")
self.health = Common.game.player.health * 2
You don’t! If you, personally, prefer to code in another way, then that’s okay!
I’m not arguing that you should code that way. I’m arguing that coding that way is valid and not as problematic as you’re suggesting.
I mean, if you know the dot-syntax, chaining it doesn’t seem that much more complicated?
It’s not the most elegant code, but it’s either that or a bunch of "getGlobalPtr"s, which to my eye look less newcomer-friendly. Or the to-be-deprecated (I gather) use of global variables (i.e. just “loader.loadModel”).
class loadMyModel():
def __init__(self):
pass
def body(self, base, model):
ob = base.loader.loadModel("Assets\Models\planet_sphere")
ComDir = r'Assets\Models\hi_res_tex\a_' + model + ".jpg"
ob_tex = base.loader.loadTexture(ComDir)
ob.setTexture(ob_tex)
return ob
def astronaut(self, base, model):
ob = base.Actor(model)
this is the trial.py
from panda3d.core import loadPrcFile
loadPrcFile("config/conf.prc")
from direct.showbase.ShowBase import ShowBase
from ModelLoader import loadMyModel
class trial(ShowBase):
def __init__(self):
ShowBase.__init__(self)
load_my_model = loadMyModel()
model = "earth_daymap"
self.main_model = load_my_model.body(model)
self.main_model.reparentTo(render)
app = trial()
app.run()
this is happening only when I am calling for the texture and the same issue is appearing with the common method too. Is there something obvious that i am missing?