2013-09-26 3 views
1

Я программирую игру в Pygame. Я продолжал сталкиваться с этой ошибкой, и я не понимаю, как ее исправить. Он запускает pauseMenu() init и печатает то, что в нем, поэтому он может запускать его, но после этого я застрял. Любая помощь будет оценена.Pygame TypeError: missing 1 обязательный позиционный аргумент:

Точная ошибка:

Traceback (most recent call last): 
    File "C:/Users/derek/Desktop/current workspace/Red_Fox/main.py", line 85, in <module> 
    start() 
    File "C:/Users/derek/Desktop/current workspace/Red_Fox/main.py", line 37, in start 
60 
    mainLoop() 
    File "C:/Users/derek/Desktop/current workspace/Red_Fox/main.py", line 67, in mainLoop 
    pauseMenu.pauseMenuFunct(DISPLAYSURF,(WINWIDTH,WINHEIGHT)) 
TypeError: pauseMenuFunct() missing 1 required positional argument: 'WINDIM' 

Главное здесь, и файл я звоню под ним.

import pygame,sys 
from Player import * 
from Block import * 
from menu import * 
from pauseMenu import * 
from pygame.locals import * 
goToMenu = True 
def start(): 
    pygame.init() 
    menuScreen = MenuScreen() 
    pMenu = pauseMenu() 

global DISPLAYSURF,BRIGHTBLUE,FPSCLOCK, \ 
     FPS,player,objects, \ 
     WINHEIGHT,WINWIDTH,goToMenu, \ 
     objectsFP,WINDIM 
FPS = 60 # frames per second to upate the screen 
WINWIDTH = 800 # width of the program's window, in pixels 
WINHEIGHT = 600 # height in pixels 
WINDIM = WINWIDTH,WINHEIGHT 
#WINWIDTH = 1920 # width of the program's window, in pixels 
#WINHEIGHT = 1080 # height in pixels 
FPSCLOCK = pygame.time.Clock() 
BRIGHTBLUE = ( 0, 170, 255) 
DISPLAYSURF = pygame.display.set_mode((WINWIDTH, WINHEIGHT)) 
FPSCLOCK = pygame.time.Clock() 
#player = Player(100,100) 
objects = [] 
objectsFP = [] 
if goToMenu: 
    goToMenu = False 
    menuState = menuScreen.menuFunct(DISPLAYSURF,WINDIM,BRIGHTBLUE) 

if menuState == 0: 
    initGame() 
    worldGen() 
    mainLoop() 
elif menuState == 1: 
    print('Will have options here') 


#global DISPLAYSURF,BRIGHTBLUE,FPSCLOCK,FPS 

def worldGen(): 
    for i in range(int(WINHEIGHT/2),WINHEIGHT,10): 
     for j in range(0,WINWIDTH,10): 
      objects.append(Block(j,i)) 
      if(i == int(WINHEIGHT/2)): 
       objectsFP.append(Block(j,i)) 
       print('happened dawg') 
    for o in objectsFP: 
     o.draw(DISPLAYSURF) 
def initGame(): 
    print('in initGame()') 
    objects.append(Player(100,100)) 

def mainLoop(): 
    while True: 
     DISPLAYSURF.fill(BRIGHTBLUE) 
     for event in pygame.event.get(): 
      if event.type == QUIT: 
       quitCleanUp() 
      elif event.type == KEYDOWN: 
       objects[0].keyDownUpdate(event) 
       if event.key == K_ESCAPE: 
        print(FPS) 
        pauseMenu.pauseMenuFunct(DISPLAYSURF,(WINWIDTH,WINHEIGHT)) 
      elif event.type == KEYUP: 
       objects[0].keyUpUpdate(event) 
     for i in objects: 
      i.update() 
      i.draw(DISPLAYSURF) 
     #objectsFP = objects.copy() 
     objects[0].objUpdate(objectsFP) 
     #player.update() 
     #player.draw(DISPLAYSURF) 
     pygame.display.update() 
     FPSCLOCK.tick(FPS) 

def quitCleanUp(): 
    pygame.quit() 
    sys.exit() 

if __name__ == '__main__': 
    start() 

Это другой класс, который я пытаюсь назвать.

import pygame,time,sys 
from pygame import * 



class pauseMenu(): 

    goToMenu = False 
    imageDict = {} 
    textDict = {} 
    rectDict = {} 
    Clicked_Button = '' 
    DarkGrey =  (134, 134, 134) 
    volume = 10 
    FPSCLOCK = pygame.time.Clock() 


    def pauseMenuFunct(self,screen,WINDIM): 
     print("made it here") 
     def check_collisions(self,pos,list): 
     # iterate dict, check for collisions in systems 
     #  print('Made it to teh da function') 
      for k,v in list.items(): 
       # print('Made into to the for loop') 
       if v.collidepoint(pos): 
        # print(v) 
        # print("clicked button:", k) 
        self.Clicked_Button = k 
        # print(self.Clicked_Button) 
        return True,k 

     WINWIDTH,WINHEIGHT = WINDIM 
     # print('Made it to the function') 
     # screen.fill(background) 
     imageDict = {'buttons': pygame.image.load('Resources/Pics/PauseOptions.png') 
     } 

     imageDict['buttons']=pygame.transform.smoothscale(imageDict['buttons'],(int(WINWIDTH*.2),(int(WINHEIGHT*.1)))) 

     buttonX,buttonY= imageDict['buttons'].get_size() 
     # print(buttonX , buttonY) 
     textSize = int(buttonY/2) 
     # print(textSize) 
     self.font = pygame.font.Font('Resources/chunkfont.ttf', textSize) 
     textOptions = self.font.render("Options", 1, self.DarkGrey) 
     textSave  = self.font.render("Save", 1, self.DarkGrey) 
     textQuit  = self.font.render("Quit", 1, self.DarkGrey) 
     textVolume = self.font.render("Volume", 1, self.DarkGrey) 
     textBackToGame = self.font.render('Return', 1, self.DarkGrey) 
     VolumePopUp = self.font.render(str(self.volume), 1, self.DarkGrey) 
     textBackToMenu = self.font.render('Menu', 1 , self.DarkGrey) 


     self.rectDict['Options'] =   screen.blit(imageDict['buttons'], (WINWIDTH/4,(WINHEIGHT/3))) 
     self.rectDict['Save'] =    screen.blit(imageDict['buttons'], (WINWIDTH/2+60.5,WINHEIGHT/3)) 
     self.rectDict['Quit'] =    screen.blit(imageDict['buttons'], (WINWIDTH/4,(WINHEIGHT/2))) 
     self.rectDict['Volume'] =   screen.blit(imageDict['buttons'], ((WINWIDTH/2+60.5),(WINHEIGHT/2))) 
     self.rectDict['Return'] =   screen.blit(imageDict['buttons'], (WINWIDTH/4,(WINHEIGHT/1.5))) 
     self.rectDict['Menu'] =    screen.blit(imageDict['buttons'], (WINWIDTH/2+60.5,WINHEIGHT/1.5)) 
     self.textDict['textOptions'] =  screen.blit(textOptions,(WINWIDTH/4 + (buttonX/4),(WINHEIGHT/3+textSize/2))) 
     self.textDict['textQuit'] =   screen.blit(textQuit,(WINWIDTH/4 + (buttonX/4),(WINHEIGHT/2+textSize/2))) 
     self.textDict['textSave'] =   screen.blit(textSave,(WINWIDTH/2+60.5 + (buttonX/3),(WINHEIGHT/3+textSize/2))) 
     self.textDict['textVolume'] =  screen.blit(textVolume,(WINWIDTH/2+50.5 + (buttonX/4.5),(WINHEIGHT/2+textSize/2))) 
     self.textDict['textBacktoGame']=  screen.blit(textBackToGame,(WINWIDTH/4+ (buttonX/4),(WINHEIGHT/1.5+textSize/2))) 
     self.textDict['textMenu']=   screen.blit(textBackToMenu,(WINWIDTH/2+60.5+ (buttonX/4),(WINHEIGHT/1.5+textSize/2))) 
     self.textDict['volumeNum']=   screen.blit(VolumePopUp,(WINWIDTH/2+55.5 + buttonX/1.25,(WINHEIGHT/2+textSize/2))) 
     pygame.display.update() 
     print('made it to the update') 


     while True: 
      self.FPSCLOCK.tick(60) 
      for event in pygame.event.get(): 
       if event.type == QUIT: 
        sys.exit() 
       elif event.type == KEYDOWN: 
        if event.key == K_ESCAPE: 
         sys.exit() 

       elif event.type == MOUSEBUTTONDOWN: 
        if event.button == 1: 
         if check_collisions(self,event.pos,self.rectDict): 

          # print('Button Clicked from Event Loop is: '+self.Clicked_Button) 

          if self.Clicked_Button == 'Quit': 
           sys.exit() 
          elif self.Clicked_Button == 'Save': 
           print('It will be saved later') 
          elif self.Clicked_Button == 'Volume' and self.volume>0: 
           self.volume -= 1 
           print(self.volume) 

           VolumePopUp = self.font.render(str(self.volume), 1, self.DarkGrey) 
           screen.blit(imageDict['buttons'], ((WINWIDTH/2+60.5),(WINHEIGHT/2))) 
           screen.blit(VolumePopUp,(WINWIDTH/2+55.5 + buttonX/1.25,(WINHEIGHT/2+textSize/2))) 

           pygame.display.update(self.textDict['volumeNum']) 


          elif self.Clicked_Button == 'Return': 
           print('This will close the menu and you return you to the game.') 
          elif self.Clicked_Button == 'Options': 
           print('This will take you to an options screen') 
           #TODO Return values 
          elif self.Clicked_Button == 'Menu': 
           print('Will take you to main menu sooner or later') 
        elif event.button == 3: 
         if check_collisions(self,event.pos,self.rectDict): 
          if self.Clicked_Button == 'Volume' and self.volume<10: 
           self.volume += 1 
           print(self.volume) 

           VolumePopUp = self.font.render(str(self.volume), 1, self.DarkGrey) 
           screen.blit(imageDict['buttons'], ((WINWIDTH/2+60.5),(WINHEIGHT/2))) 
           screen.blit(VolumePopUp,(WINWIDTH/2+55.5 + buttonX/1.25,(WINHEIGHT/2+textSize/2))) 

           pygame.display.update(self.textDict['volumeNum']) 

           #TODO Return volume values 


    def __init__(self): 
     print('PauseMenu _init_ ran') 
+0

Возможный дубликат [Python class missing positional argument] (http://stackoverflow.com/questions/19370336/python-class-missing-positional-argument) – Basilevs

+0

Этот вопрос старше, чем вы упомянули. Этот вопрос также год и наполовину старый. Теперь нет необходимости пытаться вызывать дубликаты. – ddaniels

+0

этот вопрос является более распространенной версией этого. И [нам нужно отметить старые дубликаты] (http://meta.stackoverflow.com/questions/255979/what-is-the-purpose-of-closing-old-duplicates?s=1|1.2889). – Basilevs

ответ

1

Вы звоните pauseMenu на самом классе:

pauseMenu.pauseMenuFunct(DISPLAYSURF,(WINWIDTH,WINHEIGHT)) 

Это несвязанная функция, поэтому self не будет заполнен для вас.

Вы также создаете экземпляр где-то:

def start(): 
    pygame.init() 
    menuScreen = MenuScreen() 
    pMenu = pauseMenu() 

Возможно, вы имели в виду, чтобы позвонить pMenu.pauseMenuFunct() вместо этого?

+0

Хорошо, что это была ошибка в конце концов. Спасибо всем, что я должен был изменить имя и добавить его к глобальным переменным. Спасибо! – ddaniels

Смежные вопросы