So I have a GOMenu function which is the screen you see when you die. Then I used wxpython to make a window so I can get the players name and store it with the persons score in a dictionary. Now in my main menu I have "Start Game, Scores<< When the person goes to that scores i want it to show a list of all the high scores in the past 30 days which I know how to acomplish that but my problem is I cannot get the data from the Class which you have to make with wxpython into this function. I want to get the HighScores dicitonary from GOMenu() so I can use it for my display of scores. Thanks! Ill be happy to answer any questions to help solve this problem.

Replies To: Help! With Getting Data!

Re: Help! With Getting Data!

Posted 25 January 2011 - 06:58 PM

A classic scoping issue.

The way I would solve this is by creating a separate class whose sole job is to be keeper of the high scores. This class would load data from a file (perhaps a pickle?) when instantiated, report the data in a dictionary/ordered list, and update the score file when saved.

Each time you want to access the high scores, you would simply need to instantiate the class and call the methods.

Your application is PySimpleApp() and you declared the variable "frame" but you didn't connect the two.

You have a custom frame (an instance of wx.Frame):

class Name(wx.Frame):
def __init__(self,parent,id):
box=wx.TextEntryDialog(None,'What is your name?','High Score Names','Enter Name Here')#Gives you a dialog box, the second parameter is the quesion, the third is the title of the box, the fourth is the default text#
if box.ShowModal()==wx.ID_OK: #So if the user clicks cancel then it wont store in the variable otherwise if you didnt you would get it stored#
HighScoreName=box.GetValue()#So if its ok then it will store it in answer
global HighScores
HighScores = {'Paul':9000000}
HighScores[HighScoreName] = Score
print HighScores

Re: Help! With Getting Data!

Posted 25 January 2011 - 08:01 PM

Motoma's way will work great and I can use it but let me try to explain what the problem is. I want to know this so if I ever encounter his again i know what to do. So I have the GOMenu function which gives me a pygame window that says prints "Game Over" and the final score. Then i use pygame.time.wait() to wait 5 seconds and then over the window a WxPython window shows up and asks the user for his name. Then i link HighScoreName=box.get_value() to store his name into that variable. Then I make a dictionary "HighScores" storing the names as the keys and the score as the value. Now ScoreMenu() is just a function to list all the scores in a pygame window. Now I need to get the HighScore dictionary from the GOMenu() in the class for wxpython. I tried making the HighScore dictionary global but it said its not defined. Now im wondering how I can get data from HighScore variable which is a dictionary to go into my function ScoreMenu(). Thanks