[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] switching between text window and graphics/game window (high score list) - crashes both text and graphics window



Hey,

you should try running it from a command prompt, that way you will see
any errors printed out before it closes.



If python does not run from the command prompt, you may need to set up
your path in your shell.  Something like this if you have python2.3

set PATH=%PATH%;c:\Python23\
cd \mygamedir
python mygame.py

Chairs.

On 4/23/05, D. Hartley <denise.hartley@xxxxxxxxx> wrote:
> Hello, Everyone!
> 
> I am working on a "mod" of the space invaders game listed in the
> samples on the pygame website.  I wanted to add a high score list, and
> figured out how to do this in the text (console) window, which is open
> behind the game window during play.
> I got in the working code to have a high score list, and it even
> saves/loads one now (!!).  The only problem is, clicking back from the
> text window to the game window (only after you entered in your name to
> go onto the high score list), closes the program. you dont get to say
> y/n to another game, it just shuts down. i cant run a debugger on it,
> because the error doesnt happen when I F5-run the game from the python
> IDLE script, only when i have ran it by doubleclicking on it (which is
> how you're supposed to run it. otherwise it doesnt shut down
> properly). i really really REALLY want to keep the high score part of
> my program, because i worked really hard to get this to work. but i
> have to have this program running with NO crashes in like a week (it's
> a birthday present, and the birthday is approaching fast!)
> 
> Here's the "end of game" code:
> 
>            #game over..
>            if lives == 0:
> ### trying addscore
> 
>                def add_score():
> #                   high_scores = [(1000,"Denise"), (945,"Denise"),
>  #                                 (883,"Denise"),(823,"Grant"),
>   #                                (779,"Aaron"), (702,"Pete"),
>    #                               (555,"Tom"), (443,"Tom"),
>     #                              (442,"Robin"), (4,"Pete")]
>                    high_scores = pickle.load(file("scores.pik"))
>                    score = total_enemy_hits
>                    if score > high_scores[-1][0]:
>                        print "Ta da! You got", total_enemy_hits,
> "Ranch Delivery Devices!"
>                        name = read_string("You made the high score
> list! What's your name? ")
>                        user_score = (score,name)
>                        high_scores.append(user_score)
>                        high_scores.sort(reverse=True)
>                        del high_scores[-1]
>                        pickle.dump(high_scores, file("scores.pik", "w"))
>                        for score, name in high_scores:
>                            slip = 30 - len(name)
>                            slip_amt = slip*" "
>                            prefix = 5*" "
>                            print prefix,name,slip_amt,score
>                    else:
>                        print "Sorry, you only got", total_enemy_hits,
> "Ranch Delivery Devices."
>                        print "You didn't quite make the high score list!"
>                        for score, name in high_scores:
>                            slip = 30 - len(name)
>                            slip_amt = slip*" "
>                            prefix = 5*" "
>                            print prefix,name,slip_amt,score
>                        print "Better luck next time!"
> 
> #               pdb.set_trace()
>                add_score()
> 
>                end.play()
>                showGameOver(screen, background_image)
>                pygame.display.flip()
> 
>                answer = ""
>                while not answer in ("y","n"):
>                   for event in pygame.event.get():
>                      if event.type == KEYDOWN:
>                         if event.key == K_n:
>                            answer = "n"
>                         elif event.key == K_y:
>                            answer = "y"
>                if answer == "n":
>                    running = 0
>                else:
>                    return 1
> 
>            #refresh the display
>            pygame.event.pump()
>            pygame.display.flip()
> 
>    #well, nice playing with you...
>    screen = pygame.display.set_mode((640, 480))
>    return 0
> 
> Can anyone tell me why it crashes? you click to the text window when
> there's the "congrats, you made the high score list, enter your name"
> prompt, enter your name and hit enter, and it displays the high
> scores, with your name in it, just as it should. but then when you
> click back to the game screen, poof! it all closes.  Of course if you
> dont make the high score list, you can click to the text window and
> click back to the game window and it operates like it should. Is there
> always a problem when entering keystrokes in the console window while
> running a game? Esp if the game operates on keystrokes too?
> 
> Any suggestions would be appreciated!!  I'd actually like to have it do
> all this score stuff in the game/graphics window, and then it wouldnt
> have that crash at all. But I dont know how to do that.
> 
> Please help!
> 
> Thanks again :)
> 
> ~Denise
>