Sinisterly
scoreboard with text file? - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Python (https://sinister.li/Forum-Python)
+--- Thread: scoreboard with text file? (/Thread-scoreboard-with-text-file)

Pages: 1 2


scoreboard with text file? - hellomen - 12-05-2013

Hi there community

I've got a little question and I've no single idea how to make this
I want to save scores in scores.txt (this is simple)
name
score
name
score

now I want to make a high score list (score sort)
but it must be signed with the username (because I already got a register and login)

I want to try it with an array but unsure how to get this step done that the score keeps with the name.

regards,
hellomen


scoreboard with text file? - hellomen - 12-05-2013

Hi there community

I've got a little question and I've no single idea how to make this
I want to save scores in scores.txt (this is simple)
name
score
name
score

now I want to make a high score list (score sort)
but it must be signed with the username (because I already got a register and login)

I want to try it with an array but unsure how to get this step done that the score keeps with the name.

regards,
hellomen


RE: scoreboard with text file? - joeb12 - 12-05-2013

You need a dictionary type structure. A dictionary is an array where the index of the array is the key like the alphabet is the key of a dictionary - suggest username as I assume is unique. Then when you sort names and scores will "stay together".
What language are you trying to implement in?


RE: scoreboard with text file? - joeb12 - 12-05-2013

You need a dictionary type structure. A dictionary is an array where the index of the array is the key like the alphabet is the key of a dictionary - suggest username as I assume is unique. Then when you sort names and scores will "stay together".
What language are you trying to implement in?


RE: scoreboard with text file? - hellomen - 12-05-2013

(12-05-2013, 12:12 PM)joeb12 Wrote: You need a dictionary type structure. A dictionary is an array where the index of the array is the key like the alphabet is the key of a dictionary - suggest username as I assume is unique. Then when you sort names and scores will "stay together".
What language are you trying to implement in?

as the section says python Smile
I am going to use easygui to show it but it's mainly the array listing

and yes the username(s) are identical

and let's this is the score:
a
1
b
5
c
3

the array would be: [a,1,b,5,c,3]

if I sort the usernames it would be a b c
if I sort the score it would be: 1 3 5


RE: scoreboard with text file? - hellomen - 12-05-2013

(12-05-2013, 12:12 PM)joeb12 Wrote: You need a dictionary type structure. A dictionary is an array where the index of the array is the key like the alphabet is the key of a dictionary - suggest username as I assume is unique. Then when you sort names and scores will "stay together".
What language are you trying to implement in?

as the section says python Smile
I am going to use easygui to show it but it's mainly the array listing

and yes the username(s) are identical

and let's this is the score:
a
1
b
5
c
3

the array would be: [a,1,b,5,c,3]

if I sort the usernames it would be a b c
if I sort the score it would be: 1 3 5


RE: scoreboard with text file? - joeb12 - 12-05-2013

http://docs.python.org/2/tutorial/datastructures.html#dictionaries
score = {'a':1, 'b':5, 'c':3}
score['a']
1
score['c']
3
score['b']
5


RE: scoreboard with text file? - joeb12 - 12-05-2013

http://docs.python.org/2/tutorial/datastructures.html#dictionaries
score = {'a':1, 'b':5, 'c':3}
score['a']
1
score['c']
3
score['b']
5


RE: scoreboard with text file? - hellomen - 12-05-2013

(12-05-2013, 12:32 PM)joeb12 Wrote: http://docs.python.org/2/tutorial/datastructures.html#dictionaries
score = {'a':1, 'b':5, 'c':3}
score['a']
1
score['c']
3
score['b']
5


but how would I get it like that 'c' : 3
out of the text file:
a
1
b
5
c
3


RE: scoreboard with text file? - hellomen - 12-05-2013

(12-05-2013, 12:32 PM)joeb12 Wrote: http://docs.python.org/2/tutorial/datastructures.html#dictionaries
score = {'a':1, 'b':5, 'c':3}
score['a']
1
score['c']
3
score['b']
5


but how would I get it like that 'c' : 3
out of the text file:
a
1
b
5
c
3