[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

VC++ 2010 - Best way to save a set of variables for an object?

This is in VC++ 2010.

I'm trying to figure out how to save this information properly and load it per game session at the moment. What I'm trying to save is a 'ship loadout'. A ship loadout would be the EQUIPMENT on a ship. All equipment have an ID, and that's all I'm trying to save, a bunch of ID's for each ship you use.

First off, it can't be static, each ship has a set have a amount of equipment slots (Which I can grab the amount per ship), but it is different per ship. I want to be able to save ship loadouts PER SHIP. (Which I'll be using the numeric keys to save and load ships.) Each ship also has an ID it can call.

So what I want is each ship ID will have ship loadouts assigned to it that can be saved or loaded for future use. I was aiming to have 3 loadouts per ship maximum, if that helps anyone. Again, all I need is the equipment IDs that can be assigned to each ship ID, which I can grab on a ship very easily. All IDS are 5 digits long.

I'm not asking for full fledged coding, I'm mainly asking for a way to store this properly, possibly with a small example using dummy coding to save.

0
Valleriani
Asked:
Valleriani
3 Solutions
 
AndyAinscowCommented:
Database with tables, referential links,  unique index's ...
0
 
jkrCommented:
One other nice way would be using XML files to save object properties. See e,g, http://www.grinninglizard.com/tinyxmldocs/tutorial0.html (TinyXML is a great library also) and especially the parts "Encode C++ state as XML" and "Decoding state from XML"
0
 
satsumoSoftware DeveloperCommented:
I understand the question but I'm not sure what the problem is?  Generating the ID's?  Saving the file? Dealing with different number of ID's for each ship?  It looks quite straightforward to me, perhaps I'm missing something.
0
 
pegasysCommented:
XML files would result in a lot of memory use, I would personally use a separate database with 3 separate tables:

SHIP [table]
ID - int
SHIPNAME - STRING

EQUIPMENT [table]
ID - int
NAME - string
FOO - string -> example
BAR - decimal -> example

LOADOUT [table]
ID
FK_SHIPID
FK_EQUIPMENTID


Hope this helps. To save/read (in pseudocode - I'm on my mac so cab to boot windows lol)

object ship
{
     int id;
     string name;
     object array loadoffs1; //collection of equipment
     object array loadoffs2; //collection of equipment
     object array loadoffs3; //collection of equipment
}

void saveship(int shipid, object ship)
{
     connect database;
     confirm data connection or die
          {
               //database connection OK
               if exists(shipid){
                    confirm update?
                    write update using shipid and objects;
               }else{
                    save new ship with objects;
               }
          }
}

void loadship(shipid){
     connect database;
     confirm data connection or die
          {
               //database connection OK
               if exists(shipid){
                    create empty ship object;
                    read database into ship object;
               }else{
                    throw exception and die; //ship does not exist
               }
          }
}

Sorry about the shoddy pseudo, but its too early and coffee hasn't kicked in :P
0
 
jkrCommented:
>>XML files would result in a lot of memory use

Um, they're stored on disk, so why would they cause memory usage?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now