Medieval Story has a profile system where each profile store that particular player's progress. A profile consists of a "saveObject" std::vector witch hold the actual npc and world object data. These data entries hold information on where an npc is located, direction, what that npc is doing (current animation) etcetera. The world objects store roughly the same data (only dynamic objects are stored, such as doors and the like).
These data entries are created for each npc and for each map... so when the player leaves a map the npc locations are stored to memory. This creates a conflict when the player revisits a map. The actual map file also holds npc data, where they initially are and what they are doing. This npc map data must be matched to the saved npc data from the profile, the profile data always takes precedence. To break things down:
1. Player arrives at a new map, never before loaded.
2. The map file has a rabbit at location X.
3. Player hunts the rabbit and kills it at location Y.
4. Player leaves the map and saves npc data to profile memory.
5. Later the player goes back to the same map with the rabbit.
6. Rabbit is again loaded at location X and alive.
7. A match takes place from the profile data and notices that the rabbit should be dead and laying at location Y. Remove this save position after it has been processed.
The last thing happening in point 7 is that the saved data gets erased. One might wonder why this is a good idea? If I don't erase the data (or match it to new data), there would be many saved states of the Rabbit laying dead in memory. In fact one entry for each time I leave the map, this is unnecessary.
This is all pretty easy to implement, just a bit tedious to get working right. Then I started to think about the scripting variables and objects dynamically created outside of the map file (using lua scripts). These must be stored as well? Yes and no. Not all variables need to be stored but some certainly needs to be stored. I am fairly new to scripting and thought I might need some help in that department. First I thought it would be easiest just to store the entire lua stack and dump it to a file somehow. Well, I quickly found out that was not the best approach. I could not find a good resource or article on how to achieve this and I also came to the conclusion that it would save much unnecessary (temporary) variables. I posted a question on the API and Tools board and got a really good reply from Ashaman73. You can read our discussion here. What it basically boils down to is saving a char buffer with a lua chunk. I save this buffer to my profile as a separate data entry (similar to my npc and object data slots). Later I load the buffer and send the data to lua when I'm reading the player profile.
This entry became longer than I thought... To finish, just a picture to show you I have been doing some graphics between programming sessions:
Time for lunch! :-) Thanks for reading!