AttributeError: World instance has no attribute 'setkey'

For some reason this code wont work, why? Trying to make a jump key with space.

self.keyMap = {"left":0, "right":0, "forward":0, "back":0, "up":0}
self.accept("space", self.setkey, ["up",1])
self.accept("space_up", self.setkey, ["up",0])

	if (self.keyMap["up"]!=0):
	    base.camera.setPos(0,0,100)
	    base.camera.setPos(base.camera.getPos() + camright*(elapsed*500))
	    base.camera.setPos(0,0,-25)

[/code]

you are just setting positions. Jumping is more complex then that. It has gravity and jump force. I suggest looking at panda build in physics lib.

The code you present seems to be part of a class “World” that you copied from some example. This class is nothing Panda3D gives to you. If you want to use a method “setkey” then you have to implement this method (or copy it from the example you used).

It should be something like:

    def setkey( self, key, value ):
        self.keyMap[ key ] = value

Oh, and watch the indention. This can never be valid python code:

self.keyMap = {"left":0, "right":0, "forward":0, "back":0, "up":0}
self.accept("space", self.setkey, ["up",1])
self.accept("space_up", self.setkey, ["up",0])

Well, ok, it can, if you use the variable “self” in a very uncommon way. But this would be very very bad Python coding style.

enn0x

I know, but I dont have physics up and running yet, just trying to learn how control works. With the jumping with positions I can get around some stuff (for fun, dont have collision up and running yet) + just testing out the accepting keys.

I do have following in the my code, I just forgot to put it in the set. I took the code from the Roaming-Ralph tut to use in my own code.