key movement...

hey, i know this is a stupid question but i can’t figure it out.
I want to make my character move but it gives an error that “self” is not defined

def omhoog(self):
	hans.setY(obj, 10)

self.accept('arrow_up', self.omhoog )

I did it like in the tutorials

self is a special keyword in python. its related to classes and instances of objects.
i recommend reading up on object-oriented programming in python to understand what self exactly is, when you need it etc. its a bit tricky to underatand but that’s advanced python basics so to say.

greetings,
thomas

ps: sry i couldnt answer the question itself since this would require to explain the OO-part of python which is out of question (at least for me).

Okay, then i ask it now.
How do i need to use the “self” in this case?
I was just searching for something like a code snippet but i couldn’t find it.

‘self’ is not defined in this case so there’s no reason to use it either.
ThomasEgi says that ‘self’ is a special keyword in Python, but it is not. It is a normal variable.

In your case:

def omhoog(self):
   hans.setY(obj, 10)

base.accept('arrow_up', omhoog ) 

I’ve replaced self.accept with base.accept (you need to call accept on a DirectObject instance, which ShowBase is.)

I recommend you to follow some Python tutorials about Object Oriented Programming / Classes.

Okay thanks it doesn’t work yet but it at least does something when i push the up arrow button(an error). Thanks, i’ll try to learn object orientation in Python.
You replied fast by the way