Highscores list

S

Shawn Minisall

I'm writing a game that uses two functions to check and see if a file
called highScoresList.txt exists in the main dir of the game program.
If it doesn, it creates one. That part is working fine. The problem is
arising when it goes to read in the high scores from the file when I
play again.
This is the error msg python is giving me

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
main()
File "I:\PYTHON\PROJECT #3\PROJECT3.PYW", line 330, in main
if(hasHighScore(wins) == True):
File "I:\PYTHON\PROJECT #3\PROJECT3.PYW", line 175, in hasHighScore
scores,names = string.split(line,"\t")
ValueError: need more than 1 value to unpack

Here's the relavant code:

def hasHighScore(score):
#opens highScoresList.txt
infile = open("highScoresList.txt",'r')
scores = [0,0,0]
names = ["","",""]

#reads in scores from highScoresList.txt
i=0
for line in infile.readlines():
scores,names = string.split(line,"\t")
names=string.rstrip(names)
i += 1
infile.close()
#compares player's score with those in highScoresList.txt
i=0
for i in range(0,len(scores)):
if(score > int(scores)):
return True
else:
return False


def setHighScores(score,name):
#opens highScoresList.txt
infile = open("highScoresList.txt",'r')
scores = [0,0,0]
names = ["","",""]

#reads in scores from highScoresList.txt
i=0
for line in infile.readlines():
scores,names = string.split(line,"\t")
scores=int(scores)
names=string.rstrip(names)
i += 1
infile.close()
#shuffles thru the highScoresList.txt and inserts player's score
if higher then those in file
i=len(scores)
while(score > scores[i-1] and i>0):
i -= 1

scores.insert(i,score)
names.insert(i,name)
scores.pop(len(scores)-1)
names.pop(len(names)-1)
#writes new highScoresList.txt
outfile = open("highScoresList.txt","w")

outfile.write (" High Score Name \n")
outfile.write ("-------------------------------------------------\n")

i=0
for i in range(0,len(scores)):
outfile.write("\t" + str(scores) + "\t\t\t" + names + "\n")
outfile.close()

And here's the call to the functions at the end of my game, included
in the error msg.

#adds player's score to high score list if high enough
if(hasHighScore(wins) == True):
setHighScores(wins,getName(wins))

And this is what the text file looks like when it happens.

High Score Name
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

highscores list 7
C# problem 1
Top 10 players minheap sort - need help 1
Having troubles with list methods 2
Python problem 1
Pointers in python? 1
HELP PLEASE 4
Chatbot 0

Members online

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top