scrollGameMenu() takes exactly 2 arguments (1 given)

I can’t for the life of me figure out why this won’t work. I did it the same way before, and it worked fine.

class InGameMenu(dObj):
		def __init__(self):
			self.menuKeys = {"enter": 0, "up": 0, "down": 0, "select": 0, "cancel": 0}
			self.options = []
			self.mainOptions = ["first", "second", "third"]
			self.selection = 0
			self.screen = "main"
			
			if mLoop.menuOpen == True:
				if self.screen == "main":
					self.accept("arrow_up", self.setKeys, ["up", 1])
					self.accept("arrow_up-up", self.setKeys, ["up", 0])
					self.accept("arrow_down", self.setKeys, ["down", 1])
					self.accept("arrow_down-up", self.setKeys, ["down", 0])
					self.accept("space", self.setKeys, ["select", 1])
					self.accept("lctrl", self.setKeys, ["cancel", 1])
				
			elif mLoop.menuOpen == False:
				self.ignoreAll()
								
		def setKeys(self, key, value):
			self.menuKeys[key] = value
			return self.menuKeys[key]
			
		def openMenu(self):
			if mLoop.menuOpen == False and mLoop.writingDone == True: #mLoop.writingDone tells it not to run if the message box is open
				mLoop.canMove = False #character can't move
				mLoop.menuOpen = True
				
			
				#Show screen
				self.showMenuScreen()
			else:
				pass
			self.scrollGameMenu()
			
		def closeMenu(self):
			mLoop.canMove = True
			mLoop.menuOpen = False
			
		def showMenuScreen(self):
			#Show screen
			self.firstScreen = OnscreenImage(image = "My Panda Games\\My Game\\PNGs\\menuScreen.png", pos = (640, 0, -480), scale = (640, 0, 480), parent = pixel2d)
			self.firstScreen.setTransparency(TransparencyAttrib.MAlpha)
			#return None
			
		def selectOption(self, selection):
			if self.screen == "menu":
				if self.options[selection] == "first":
					pass
				elif self.options[selection] == "second":
					self.screen = "second screen"
			#return selection
					
		def scrollDown(self):
			if self.selection < len(self.options) - 1:
				self.selection += 1
			elif self.selection  == len(self.options) -1:
				self.selection = 0
			print(self.selection)
			return self.selection
			
		def scrollUp(self):
			if self.selection > 0:
				self.selection -= 1
			elif self.selection == 0:
				self.selection = len(self.options) - 1
			print(self.selection)
			return self.selection
			
		def scrollGameMenu(self, task):
			if mLoop.menuOpen is True:
				if self.menuKeys["up"] != 0:
					self.scrollUp()
				elif self.menuKeys["down"] != 0:
					self.scrollDown()
				elif self.menuKeys["select"] != 0:
					self.selectOption(self.selection)
				else:
					pass
			return task.cont
		
	gMenu = InGameMenu()
	
	#Wait for keypress
	base.accept("enter", gMenu.openMenu)
	base.taskMgr.add(gMenu.scrollGameMenu, "Scroll")
  • All of this is nestled inside a function called main(), which is the second-to-last function in the script.

  • The Task class is declared outside main() like this:

from direct.task import Task
  • The Direct Object class is declared outside main() like this:
from direct.showbase.DirectObject import DirectObject as dObj
  • mLoop stands for “main loop” and is declared outside of the class (but still inside the main function).

I think it’s trying to pass an argument to scrollGameMenu(). I just don’t know why.

It looks like a problem with your indentation (unless it is just an error in pasting the code).
You create your instance of the class:

   gMenu = InGameMenu()

actually indented inside of the class InGameMenu, trying to make an instance of a class from within the class itself.

Also not sure why you are putting the class inside of a function, that is asking for trouble. Put the class outside of the main function and create your instance of it inside the main function.

Yeah, that was just a pasting error.

My code’s so messed up, I don’t even know how to rearrange it to make that work. I tried and some of my global variables (the mLoop – main loop – variables) didn’t work. This is just part of a much larger script.

Looking at the actual error, your task function is only being passed one parameter. This leaves two possibilities:

The one parameter being passed is “task”, meaning the function is not being provided with “self”. This could happen if you are adding a task pointing to the function on the class itself instead of an instance of the class.

OR

The one parameter being passed is “self”, meaning the function is being run not as a task. This could happen somewhere else in your code, or for example if you added parentheses at the end of the function by mistake when adding a task to the taskMgr.

Okay, I got it to work. I moved the key events and taskMgr.add inside of openMenu(). I think I know why that worked, but I don’t know how to put it into words. :stuck_out_tongue: