Hello World issue

Hi guys.

First - thanks for all the insight over the last couple of days. Your input has saved me time and helped me make a lot of decisions.

So, I’ve got a small list of projects to complete, the sole purpose of which is to learn the engine. The first thing I did was install Panda on Fedora 12. After a couple hours of dependency heartache, I got Panda in and even ran the first bit of the manual - where you get a gray screen.

The next section uses this code:

from direct.showbase.ShowBase import ShowBase
class MyApp(ShowBase):
    def __init__(self):
        # Load the environment model.
        self.environ = self.loader.loadModel("models/environment")
        # Reparent the model to render.
        # Apply scale and position transforms on the model.
        self.environ.setScale(0.25, 0.25, 0.25)
        self.environ.setPos(-8, 42, 0)
app = MyApp()

I created the file in vi and saved it. I immediately get an error saying that “self” had not been properly declared or something - (I’m in Windows right now…). Then, I read that Python is picky about tab indents - which I had used in vi. So, I took them out and saved - got the same error.

In despair, I installed Panda on XP, copied the code off the site into Notepad and ran - no errors and the scene rendered. I put the tabs back in - it STILL RAN.

Could vi be putting in characters that Python can see and doesn’t like?

Ok, the actual error is:

self.environ = self.laoder.loadModel("models/environment")
NameError: name 'self' is not defined

I copied and pasted the same code from the site into Gedit, saved it and ran it - it ran fine. So, I set vi encoding to UTF-8 and saved its file and ran - still no go.

So, it looks like a Python syntax issue.

First thing: why do you use vi instead of vim (vi improved)?

Second: have you replaced all tabs by 4 spaces?
One space too much or too little can end with a fatal error. Also never mix tabs with spaces.
Other than that, i have no idea what the problem could be. Maybe some old vi weirdness. Try again with vim (which i use every day for coding, btw, also in conjunction with panda).

Bingo - that’s what it was. It might be time for me to pick up a Python book.

Thanks heeps!

Incidentally, I AM using VIM :slight_smile:, I usually just don’t have a reason to differentiate because at best people start holding up crosses and throwing holy water around.