views:

56

answers:

1

Hello!

I'm trying to make a role-playing game, and I want the game to work so that it transitions to the battle NIB for battles, then returns back to the map NIB afterward, yet still retain all the progress the player has made exploring the dungeon.

I've tried proto-typing this with just a view-switcher, where one view creates content, and then switches to the other view, and then coming back from the other view. However, once the view goes back to the original, the original view is reset.

How do I make the data persistent so that it doesn't reset after every "battle"?

Thanks!

+1  A: 

In the model view controller paradigm, you would have a model object that manages the data and a view object that displays the data. When switching from one view to another, you can discard the old view and just store the model objects. You might even write your model object to store data on disk, so you can restore state across launches.

A controller in this scenario would create and destroy the view and pass it the appropriate model object.

drawnonward
Even after creating a 1-To-Many relationship with 1 class using two NIB files for views, I'm still getting the first view reset. Mind giving me a little more in-depth advice? Thank you for your help so far!
Also, would I be using 2 NIB files in this instance, or two UIViews inside of 1 NIB? Thanks!
Let us assume you have an NSMutableDictionary that represents all the progress the player has made exploring the dungeon. You have some persistent object in your application, such as the application delegate, that holds onto that dictionary. When your map view loads, on viewDidLoad, it asks for a reference to that dictionary so it can display the current state. Any changes to the map are set in the dictionary while the map view is active. When the map view is dismissed, the dictionary still has the state for next time.
drawnonward
An NSMutableDictionary would only be an appropriate choice for a fairly simple data set. You have to choose what fits your needs. The point is to separate the storing of the data from the display of the data.
drawnonward
Drawnonward,Let me see if I understand what you're saying...So, I would have an NSMutableDictionary that would contain all the concealed quadrant pieces (let's say "A1" though "D4"), and have them be stored as items within the AppDelegate.Then, whenever the "ViewDidLoad" method is called within the Map class, it would check to see which items were invalid, and return "nil", and remove those concealed portions from the map, leaving the ones that still exist intact?Am I on the right track here?Thank you for your input so far!
That sounds right. The main thing is that the state of the map is stored outside the map view, and when the map view loads it can apply a current state. When a new game starts, the map state will be empty. As a game progresses, the state will change. Each time the map view loads, it displays the state.
drawnonward
Got it! So my app delegate will determine the state from outside the Map class, and then it will be called accordingly. Thank you very much! :D