hi!
i have a problem with saving something and am officially out of ideas. what i want to do is save an integer array into the userDefaults, then when restarting the app loading this array and restart the game from this last point.
what i do is that after each turn my AI logic saves the actual game state into an array -> so far so good this works fine. the array is saved and when i "re"read the saved array it seems ok... well actually it has saved the correct array!
now i restart the game. i check for a bool variable that i also saved if the game was interrupted out of the orderly. works fine too.
now the trick part. i read the array from the userDefaults and WOHOOO! i get a slighty different array then i saved! i really really cant figure out why :(
well: now the code:
here is what i do to save the board:
NSData *data = [NSData dataWithBytes:&boardToSave length:sizeof(boardToSave)];
[userDefaults setObject:data forKey:@"MB_boardSave"];
and here what i do to get the data back when initialising the board:
int loadBoard[8][8] = {0};
NSData *data = [userDefaults objectForKey:@"MB_boardSave"];
memcpy(&loadBoard, data.bytes, data.length);
again... whats going in is correct, whats coming out is not :(
any suggestions would be very much appreciated! i´m also open to alternative saving options if you think there are better ones!
thx