hello world example

Been away from panda for a bit and just came back. love the new site’s look and organization.

I downloaded 1.7 and was glad to see the code I’d written in 1.6 was still running fine. Reading through the manual, I noticed the newer way (to me anyway) of structurung the program. Namely:

from direct.showbase.ShowBase import ShowBase 
class MyApp(ShowBase):     
def __init__(self):        
ShowBase.__init__(self) 

app = MyApp()
app.run()

so i modified my code a bit to do it this way. I had code like this:

import direct.directbase.DirectStart
from direct.showbase import DirectObject

class MyGame(DirectObject.DirectObject):
	def __init__(self):

g = MyGame()
run()

Like I said my code worked fine, but after I changed it - it bombs out with exit code 1.
Can’t find a reason why. I even created a new py file with just the 6 lines in my first code example (right from the manual) and panda won’t start up.

What am I missing? Thx
[/code]

Hmm, is it possible you still have a reference to DirectStart somewhere, even after the new change? You must not import DirectStart if you are creating your own ShowBase instance.

David

yes , i thought there could be something in my code, so I started jsut trying to run this 6 line program.

from direct.showbase.ShowBase import ShowBase 
class MyApp(ShowBase):      
def __init__(self):        
ShowBase.__init__(self) 

app = MyApp() 
app.run() 

and same problem (no panda window and exit code 1).

Very strange.
I will try rebooting my pc (when in doubt …)

Hmm, works fine for me, after I correct the indentation, of course.

Is your panda working in general? Does it still work if you go back and try the DirectStart approach again?

David

ah - figured it out
right before I started up the class i had this line

GAME_FONT = loader.loadFont(GAME_DIR + “/art/gui/” + “gnatfont.ttf”)

and the loader object obviously doesn’t yet exist.

Which module should i be importing for loader? thx

It’s ShowBase’s job, so do it after MyApp().

sorry for being slow on this but how do i get loader into my code?
I’d like to use loader without using this line:
import direct.directbase.DirectStart

Im trying
from direct.showbase.Loader import Loader
and
from direct.showbase.Loader import *
but no luck.

OK, thing i’ve figured it out, but want to post in case I’m not doing it the right way.

I moved the font line into my game class init

self.GAME_FONT = loader.loadFont(GAME_STORY + “/art/gui/” + “gnatfont.ttf”)

and changed any references to GAME_FONT to self.GAME_FONT

seems OK now

Yeah, this is exactly why I revamped the A Panda Hello World tutorial to use ShowBase instead of DirectStart. The old way got people dependent on everything being up and ready to go after a single import line.

‘loader’ is a member of ShowBase, though it is also stashed into builtins to make Python treat it as a built-in function (along with the likes of hasattr() and isinstance()), which means the user can call it anywhere in the entire program without importing a thing. This is why you can run even self.GAME_FONT = loader.loadFont() without it crashing. Since your program’s main class is inheriting from ShowBase, you could also write self.GAME_FONT = self.loader.loadFont(). The point being that it’s ShowBase.loader that you’re using.

Yeah, the new way it’s set up is definitely more logical. I just had to realize loader was part of showbase.

Thx for the reply!