views:

20

answers:

0

Hi!

i've been trying to make a system in which i can record the scores of a game, linked with the profile of the player being used. I am not using any on-line leaderboard system (yet), at present I just need to have a score system at its basics.

I have managed to make it that the method I am using obtains the score and the profile being used with the score, but after that I am a bit hesitant.

I want to be able to have a highscore screen in which I can show the high scores and the profiles which made them.

NSMutableDictionary seems to be the right way to go, but I am hesitant on how to use it since I am not convinced I could do everything I need to with it. I have developed the following code:

profileNames = [NSMutableArray array];
    [profileNames addObject:n];
    [profileNames retain];

    profileScores = [NSMutableArray array];
    [profileScores addObject:sco];
    [profileScores retain];

    NSNumber *temp = [NSNumber numberWithInt:10];
    NSMutableDictionary *savedData = [NSMutableDictionary dictionaryWithObject:temp forKey:@"Simon0"];
    int t2 = [savedData count];
    NSString *key= [NSString stringWithFormat: @"%@%d", n, t2];
    [savedData setObject:sco forKey:key];
    [savedData retain];
    NSLog(@"data=%@",savedData);

n is the profile and sco is the score associated with it. I have currently set it so that both values are recorded in arrays (since i originally considered using 2 arrays to sort and display the information. However, since I have been told that this is needlessly complex, i am trying with the NSdictionary.

I have the dictionary created with a test value in it and I thought that the method I have currently would prevent any doubling up of keys. Sadly, this means that the names portrayed with all have names and I dont really want that.

What I am asking is if anyone knows of a way to use arrays with dictionaries which allows you to record a name and a score so that if the score is sorted into a new array, the correct associated name is placed with it?

(I have tried reading a couple of books and some online tutorials, but I am just ended up becoming rather confused with the suggestions. I would appreciate any help anyone is willing to give. Thank you).