471,342 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

Highscores list

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[i],names[i] = 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[i],names[i] = string.split(line,"\t")
names[i]=string.rstrip(names[i])
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[i])):
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[i],names[i] = string.split(line,"\t")
scores[i]=int(scores[i])
names[i]=string.rstrip(names[i])
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[i]) + "\t\t\t" + names[i] + "\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.

Dec 8 '07 #1
0 1108

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by massimo | last post: by
24 posts views Thread by Robin Cole | last post: by
4 posts views Thread by JS | last post: by
3 posts views Thread by chellappa | last post: by
reply views Thread by drewy2k12 | last post: by
2 posts views Thread by Kasya | last post: by
6 posts views Thread by Shawn Minisall | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.