Storing player information
Storing player information
I am not familiar with SQL. Its something I will learn, but probably not in the near future. I am wondering with the entire rewrite of the Eventscripts engine into Source-Python if it would be feasible to include the cPickle engine. Would I be able to copy/paste it into "_engines" or if there would be another method?
http://docs.python.org/3.1/whatsnew/3.0.html#library-changes
Search that page for cPickle to understand the changes made in Python3.
Satoon
Search that page for cPickle to understand the changes made in Python3.
Satoon
Having some problems when loading the information. Whenever the new information loads and gets saved, it acts as if no existing data was loaded and overwrites with entirely new data.
Syntax: Select all
@Event
def round_prestart(game_event):
loadDatabase()
for players in CPlayerGenerator():
dndPlayer(players) # The class saves players into the global dictionary, player_database{}
@Event
def round_end(game_event):
saveDatabase()
msg('No more XP saved this round!')
def loadDatabase():
global player_database
str_path = ADDON_PATH.join('dnd') + '/player_database.db'
if os.path.isfile(str_path):
file_users = open(str_path, 'rb')
player_database = pickle.load(file_users)
file_users.close()
msg('Levels loaded')
def saveDatabase():
global player_database
str_path = open(ADDON_PATH.join('dnd') + '/player_database.db', 'wb')
pickle.dump(player_database, str_path)
str_path.close()
msg('Levels saved')
You should only ever load the data once, on script load: Satoon
Syntax: Select all
# Store the data as an empty dictionary in case the database has never been stored
player_database = {}
# Get the Path instance to the database file
data_path = ADDON_PATH.joinpath('dnd', 'player_database.db')
# Does the database file exist?
if data_path.isfile():
# Open/close the database file in read/byte
with data_path.open('rb') as file_users:
# Load the database into the global variable
player_database = pickle.load(file_users)
@Event
def round_end(game_event):
saveDatabase()
def saveDatabase():
# Open/close the database file in write/byte
with data_path.open('wb') as file_users:
# Dump the database
pickle.dump(player_database, file_users)
I'm not sure why it would be blank information. However, as I said, you should only load the data once. Loading it again is just loading the same data that you already have loaded. This is pointless.
In order to answer your question, I would probably need to see a lot more of your code. Specifically the dndPlayer function and any other function having to do with player_database.
Satoon
In order to answer your question, I would probably need to see a lot more of your code. Specifically the dndPlayer function and any other function having to do with player_database.
Satoon
Return to “Plugin Development Support”
Who is online
Users browsing this forum: Bing [Bot] and 142 guests