As I can see, you have some bugs with data reset and data storage in general. I was wondering why you store data in a .txt file and not into a database, like an SQLite3/SQL/MongoDB base even connected to a PHP server to store the data from every single player.
Python uses sqlite3 by default to manage Databases.
![image](https://user-images.githubusercontent.com/63709477/87876578-4f13b800-c9d9-11ea-924d-719eee9e5b2a.png)
But it's also a good idea to use a nonrelational database system (DB) as MongoDB and pyMongo
![image](https://user-images.githubusercontent.com/63709477/87876053-9730db80-c9d5-11ea-822e-cb3492d5bcc8.png)
In both cases is very simple to connect to the DDBB using python. I like to use functional decorators to do it but you can use other structures.
import sqlite3
def sqlconnect(func):
def connect_to_sql( ):
con = sqlite3.Conexion( )
func( )
con.close( )
return connect_to_sql
@sqlconnect
def connect_and_say_hi( ):
print('I am connected')
#Add data or do something
And a tip; if you need to store data in local you should use a binary file, not a text one, and even convert the info to binary using Python itself.
data.txt / data
You can use the following code to change from text to binary using Python
foo = 'Hi, I am a text'
binary = ' '.join(format(ord(letter), 'b') for letter foo) #Change the text to binary
print(str(binary))
01001000 01101001 00101100 00100000 01001001 00100000 01100001 01101101 00100000 01100001 00100000 01110100 01100101 01111000 01110100
And then open a file in write mode with the pickle module
import pickle
file = pickle.open('data/file_to_open', 'w') #write mode
file.write(binary)
file.close( )
So, the code to open a binary something in a binary file would be:
user_data = ''
binary = ' '.join(format(ord(letter), 'b') for letter in user_data) #Change the text to binary
import pickle
file = pickle.open('data/file_to_open', 'w') #write mode
file.write(binary)
file.close( )
![image](https://user-images.githubusercontent.com/63709477/87876568-30adbc80-c9d9-11ea-8e39-43eefec54059.png)