0

The code I'm having problems with is below. Can someone help me figure out how to fix this error? I'm trying to make is so that when I click start game, it calls the line in main() under the if statement.

Error:

    Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 122, in <module>
    main()
  File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 75, in main
    controller = Manager(screen)
  File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 23, in __init__
    self.go_to(TitleMenu(screen))
  File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 47, in __init__
    self.main_loop()
  File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 54, in main_loop
    self.menu.update(events)
  File "C:\Users\Administrator\PycharmProjects\untitled\menumaker.py", line 46, in update
    self.options[self.option][1]()
  File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 38, in <lambda>
    self.menu = makeMenu(["START GAME", lambda: run()], ["CONTROLS", lambda: Help(screen)], ["QUIT GAME", sys.exit])
TypeError: 'bool' object is not callable

Code:

class Manager(object):
    def __init__(self, screen):
        self.go_to(TitleMenu(screen))

    def go_to(self, scene):
        self.scene = scene
        self.scene.manager = self
#////////////////End Manager//////////////#
def run():
    global run
    run = True
    pass

#////////////////Title Menu and End Menu//////////////#
class TitleMenu(object):
    def __init__(self, screen):
        self.screen = screen
        self.menu = makeMenu(["START GAME", lambda: run()], ["CONTROLS", lambda: Help(screen)], ["QUIT GAME", sys.exit])
        self.menu.set_highlight_color((255, 0, 0))
        self.menu.set_normal_color((255, 255, 255))
        self.menu.center_at(300, 400)
        self.titleBackground = pygame.image.load("titleBackground.png")
        self.clock = pygame.time.Clock()
        events = pygame.event.get()
        self.menu.update(events)
        self.menu.draw(self.screen)
        self.main_loop()
        self.run = False

    def main_loop(self):
        while 1:
            self.clock.tick(60)
            events = pygame.event.get()
            self.menu.update(events)
            for e in events:
                if e.type == QUIT:
                    pygame.quit()
                    return

            self.menu.draw(self.screen)
            pygame.display.flip()

    def go_(self):
        self.manager.go_to(GameLevel(0))

class EndMenu(object):
    pass
#////////////////End Title Menu and End Menu//////////#

def main():
    globals()
    pygame.init()
    screen = pygame.display.set_mode(DISPLAY, FLAGS, DEPTH)
    pygame.display.set_caption("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    controller = Manager(screen)
    timer = pygame.time.Clock()
    running = True

    while running:
        timer.tick(60)
        if pygame.event.get(QUIT):
            running = False
            return

        controller.scene.handle_events(pygame.event.get())
        controller.scene.update()
        controller.scene.render(screen)
        pygame.display.flip()

        if run:
            controller.scene.go_()

    return Rect(left, bottom, width, height)

if __name__ == "__main__":
    main()

1 Answer 1

3

The problem is that your global variable run is getting confused with the run function:

def run():
    global run
    run = True
    pass

This means when you try to call run():

    self.menu = makeMenu(["START GAME", lambda: run()], ["CONTROLS", lambda: Help(screen)], ["QUIT GAME", sys.exit])

it tries to call the boolean variable. To fix it, rename the global variable is_running, or rename the function start_running.

Sign up to request clarification or add additional context in comments.

2 Comments

ok that fixed the error but now when I run it nothing happens it just sits there instead of running the function, and when I quit I get an error saying "video system not initialized"
@user1758231: That sounds like a completely unrelated error. You should try debugging it, and if you can't figure it out you can open a new question. (But just in case- what does your new run function look like, and the new makeMenu line?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.