Invalid Syntax Error at self.

Greetings

I’m trying first examples with panda and was stuck on a problem.
Here is my error message


import StartMenu

File “E:\Panda3D-1.0.5\python\lib\ihooks.py”, line 397, in import_module
q, tail = self.find_head_package(parent, name)
File “E:\Panda3D-1.0.5\python\lib\ihooks.py”, line 433, in find_head_package
q = self.import_it(head, qname, parent)
File “E:\Panda3D-1.0.5\python\lib\ihooks.py”, line 486, in import_it
m = self.loader.load_module(fqname, stuff)
File “”, line 22, in load_module
File “E:\Panda3D-1.0.5\python\lib\ihooks.py”, line 270, in load_module
m = self.hooks.load_source(name, filename, file)
File “E:\Panda3D-1.0.5\python\lib\ihooks.py”, line 168, in load_source
return imp.load_source(name, filename, file)
File “StartMenu.py”, line 25
self.startButton = DirectButton(image=’./models/Textures/StartGameButton.png’,command = self.startGame,scale=(0.6, 0.1, 0.0
^
SyntaxError: invalid syntax


Because of the wrap around issue just be aware that the Caret sign is pointing to self.startButton

This StartMenu class is identical to the one in Airblade.
So I was wondering what the problem was ?

Anyone run into this ?
I tried changing the name of startButton to startButtonX to see if startButton was a reserved word. To no avail
I tried getting rid of self. assuming it might be redundant. to no avail it just points at startButton in that case and says invalid Syntax

I tried putting ppython.exe in the same folder then it said it could not find the Panda’s Tree root. Could someone explain the path that it was looking for as a secondary question?

Why would it point to self.whatever and say self is invalid syntax ?

I was playing around with Airblade’s code and observed the same problem . i just reinstalled Airblade’s code and that problem went away.

Help

however if I leave ppython in the bin then it simply keeps pointing to self.startbutton

Which is exactly the same code as that used in Airblade?

I could offer more if you posted the code you’re using, but i think there is a syntax error before self.startButton. This is an error in the python syntax not caused by panda.

Jep I think this

DirectButton(image='./models/Textures/StartGameButton.png',command =

is the matter
command= … you have to specify something
Post the DirectButton and the self.startGame… lines if you cant fix it. But please use the code function

Martin

# Author: Stephen Sutherland
# Created: Jan 4, 2006 3:38AM
# Last Updated: 1/1/2006; 1/11/2006 
# Description:
###########################################################

from direct.showbase.ShowBaseGlobal import *
from direct.gui.DirectGui import *
from direct.showbase import DirectObject 

########################################
#     Creates a Title Screen Menu      #
########################################
class StartMenu(DirectObject.DirectObject):
    def __init__(self):
 
	base.setBackgroundColor(0, 0, 0)
	
	########################################
	# Loads up Title Screen Menu
	########################################

	self.title = DirectLabel(image='./models/Textures/splash-screen.png', scale = 1.2)
    self.title.setPos(0, 0, 0.12) 
	
	self.startButtonX = DirectButton(image='./models/Textures/StartGameButton.png',command = self.startGame,scale=(0.6, 0.1, 0.04), relief = None)
	self.startButtonX.setTransparency(1)
	self.startButtonX.setPos(-0.3, 0, 0.1)

Actually I just stripped down the code to

self.title = DirectLabel(…)
self.title.setPos(…)

and it gave me what i think is a useful error message.
It says NameError: name ‘self’ is not defined.

File “StartMenu.py”, line 24, in StartMenu
self.title.setPos(0, 0, 0.12)
NameError: name ‘self’ is not defined

Anyone have any idea how that could happen ?

I’m calling this function from my main class the same way it is called in the Airblade sample code.

By the way i’m using Panda 1.0.5

the spacing of self.title.setPos(0,0,0.12) looks like it has an extra space character. Line it up with the rest of the code.

Also, you need to make sure that the code in your init function is indented more than the the line where you define init. That could be why it is giving you the ‘self not defined’ error.

Thanks Russ;

You put me on the right track and I figured it out.

My indentation block was fine.
It turns out that this program is very particular about weather or not a new line is tabbed as opposed to simply putting 5 white spaces before the next line.

Deleting the white space between it and the previous line, then hitting return and tab fixed it.

Oh well I guess by posting this no one will have to struggle for days with this type of an issue again.