machine = Stack() #make a new stack machine.push(menuState()) #add a few menustates to cycle through machine.push(menuState()) while machine.ready() == 1: #while there is a state on the stack keep running currentState = machine.top() #grab the current state off the top of the stack if machine.needInit() == 0: #if this is the first run of this state do init() currentState.init() currentState.update() #run the update() of this state currentState.draw() # run the draw() of this state if machine.needsPop(): #needsPop() checks the currentState.run and returns accordingly machine.pop()