Re: Audiogame Map with Python

The problem may be the order in which your doing your checks, for example if you try and check if the current position in maplist - 1 is "w" without first checking if thats in bounds of the map, it will throw a list index out of range exception. Try putting your out of bounds checks ahead of your type checks. Another thing is that when using negative numbers on a list it can loop over to the end of the list, so going "list[-1]" will give you the last item in the list, where as using a positive number greater than the list length will throw an exception. Try this:


                # Moving east
                if event.key == pygame.K_RIGHT:
                    if self.currentPosition[1]+1 <= len(self.mapList[0])-1:
                        if self.mapList[self.currentPosition[0]][self.currentPosition[1]+1] == "w":
                            s().output("Wall, can't go that way", interrupt=True)
                        elif self.mapList[self.currentPosition[0]][self.currentPosition[1]+1] == "p":
                            self.currentPosition[1] += 1
                            s().output("path", interrupt=True)
                    else:
                        s().output("Wall, can't go that way", interrupt=True)


_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Victorious via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : TJ . Breitenfeldt via Audiogames-reflector

Reply via email to