confusing syntax error?

can someone check this piece of code for a syntax error?
I can’t seem to find it.


import bge
import aud
import config

def PlaySound(soundconfig):
    """ put the config sound variable into soundconfig so it plays """
    aud.device().play(aud.Factory(bge.logic.expandPath(soundconfig))

def main():
    """ calls the system  """
    ray = cont.sensors['Ray']
    if not ray.hitObject:
        sdObject = None
    else:
        sdObject = ray.hitObject.getPropertyNames()


for some reason I can’t seem to find the problem.
a lot of thanks for the one who can help me.

Usually the console is a bit more specific than just “syntax error”; it would be of assistance in troubleshooting. Anyway, I see that in the main function you refer to cont without defining it previously.

As a side note, I would probably separate the playing of sounds from the creation of them for later use. It’d probably be better to store the factories previously, and then play them back later at will.

the error simply states syntax error in the console. it points at def main() the f of def to be precise.
I am thinking of buffering them all, they are 63 in total and the size is around 200kb.
this script is still a draft for testing purposes, so I am trying out different ideas.

You’re missing a close parenthesis on the previous line. Often syntax errors will show up after they actually occur because the parser won’t recognize a problem until it encounters an unexpected expression.

Usually if the console says just “syntax error”, the script is incomplete.

This should work:


import bge
import aud
import config

cont = bge.logic.getCurrentController()
sdObject = None

def PlaySound(soundconfig):
    """ put the config sound variable into soundconfig so it plays """
    aud.device().play(aud.Factory(bge.logic.expandPath(soundconfig)))

def main():
    """ calls the system  """
    ray = cont.sensors['Ray']
    if not ray.hitObject:
        sdObject = None
    else:
        sdObject = ray.hitObject.getPropertyNames()
main()

Also, you don’t have to import bge. It’s already there. (Totally forgot the word for that. This is gonna bug me… :s)

Ok thanks, I just overlooked the bracket every time I looked.