Search code examples
pythonpython-2.7pygame2d-games

How to make a function that lets the user make a Yes/No decision


I'm creating a Game using pygame on python and attempting to allow the user to make a Yes or No Decision, but for some reason it doesn't enter my loop "for event in pygame.event.get():"

It doesn't create any error messages in the Shell, and rather than doing what I want it to do, it just bypasses the function when I press space, while nothing else seems to do anything.

Here is the function that calls the Y/N function:

if SwordCheck == None:
    dispOnTextBox("You don't have", 'anything to buy.', '')
elif SwordCheck == False:
    displayMoney(Kelts, Parts, Shreds)
    dispOnTextBox('Do you want to', 'purchase that?', "it's 200 kelts")
    VALUE = waitForYNDecision()
    if VALUE == None:
        pygame.display.update()
        FPSCLOCK.tick()
    elif VALUE == False:
        dispOnTextBox('No? Ok, but please', 'put it back when', "you are done")
        return False
    elif VALUE == True:
        dispOnTextBox('Alright! here you', 'go. Thank you', 'for your purchase')
        return True

And here is the Y/N function:

print 'CHOOSE Y/N with Up = Yes and Down = No'
for event in pygame.event.get():
    if event.type == QUIT:
        terminate()
    elif event.type == KEYDOWN:
        if event.key in (K_W, K_KP8):
            return True
        elif event.key in (K_S, K_KP5):
            return False
return None

I've tested all the other functions and its only these that have the problem. I'm an amateur at this and would appreciate a good answer.


Solution

  • Its expecting the user to do it instantly, i'm not sure if this its the intention but if it isn't just put it in a while True loop