Just a little more meat on this problem because this has me going cross eyed now.
This code should close the program when space is press but it doesn’t any idea why?
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
from direct.gui.DirectGui import *
from math import sin, cos, pi
from random import randint, choice, random
class World(DirectObject):
def __init__(self):
#set up the environ mint
base.setBackgroundColor(0, 0, 0)
base.disableMouse()
self.keys = {"turnLeft" : 0, "turnRight": 0, "accel": 0, "fire": 0}
self.accept("escape", sys.exit) #Escape quits
#Other keys events set the appropriate value in our key dictionary
self.accept("space", self.setKey, ["fire", 1])
self.gameTask = taskMgr.add(self.gameLoop, "gameLoop")
def setKey(self, key, val): self.keys[key] = val
def gameLoop(self,task):
if self.keys["fire"]==0: sys.exit
return Task.cont
w = World()
run()
Good question. It does “work” but sys.exit is not closing panda3d, Im thinking it has something to do with the taskMgr stopping the closure as its waiting for a return value from the main loop.