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
-------------------------------------------------
15 SHAWN
0
0
The answer is probably simple, I've just been working on this program so
long that my brain has turned to mush. Any help would be much
appreciated...thanks.
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
-------------------------------------------------
15 SHAWN
0
0
The answer is probably simple, I've just been working on this program so
long that my brain has turned to mush. Any help would be much
appreciated...thanks.