Code does not do anything?

def __init__(self):
	self.acceptonce("a", self.moveleft)

def moveleft(self):

I’ve been working hours on figuring out why this wouldn’t work.

Could you please describe what you mean by “wouldn’t work”? Is the code above giving an error message? If so, please post the error message. Otherwise, please describe what you are expecting to see and what you are seeing.

Could you post the whole, original code? As-is, the code has several errors, such as the use of “acceptonce” instead of “acceptOnce”, and “setpos” instead of “setPos”, wrong intendation level for “def moveleft”, and it doesn’t show what you are intending to call “setPos” on.

It doesn’t give me an error, just pressing A does nothing. The entire code is under a class. I’d assume that Self would know I am referring to the class I set up. The class is the entire Model so fari think.

Here’s the code minus all of that showbases and directs on top.

class Window(ShowBase):
	Whiskers = loader.loadModel((redacted)) #The character.
#end making the model

	#Start moving left
	def __init__(self):
		self.acceptOnce("a", self.moveleft)
	def moveleft(self):

Well, you’re calling setPos on the ShowBase instance, and not on the model. ShowBase doesn’t have a setPos(), so I would expect you to get an error message.

You probably meant to do self.Whiskers.setPos(30, 0, 0), though the lack of error indicates that maybe your moveleft() function isn’t being called at all.

I did a little test and tried putting moveleft() underneath
the code and it gave me an error saying that it wasn’t
defined… even though it is?

NameError: name ‘moveleft’ is not defined

You would need to call self.moveleft(), since it is defined as a method on the Window class, so you should call it on an instance of your Wnidow class.

Yeah still nothing. Trying to use Ralphie code doesn’t make it do anything either. This is where i am at now

    def __init__(self):
    	self.keyMap = {
		"left": 0, "right": 0}
	self.accept("arrow_left", self.setKey, ["left", True])
	self.accept("arrow_right", self.setKey, ["right", True])
	def moveleft(self):
		if self.keyMap["left"]:
			self.Whiskers.setH(self.Whiskers.getH() + 300 * dt)
		if self.keyMap["right"]:
			self.Whiskers.setH(self.Whiskers.getH() - 300 * dt)

In addition I noticed Ralphie doesn’t use such a thing at the bottom.

from direct.showbase.ShowBase import ShowBase

class Window(ShowBase):

    def __init__(self):
        camera.set_pos(0, -10, 0,)

        self.Whiskers = loader.loadModel("box") #The character.

        self.acceptOnce("a", self.moveleft)
    def moveleft(self):

app = Window()

Did you want this?

1 Like

Huh. That actually worked, thanks.