2

I want to make an interactive fiction game editor, in this type of games a story has many story-lines where each gamer can finish the game with a different story. For each section of a game story we need a node that tells the story and interacts with player.

I will make an editor for drawing story sections (nodes), that every node can link to minimum one node and maybe many, also each node has some properties (like text, photo, sound, ...) and variables (like gold on the ground, HP reducer, ...) that must be used in the game story.

What's the best way for saving this story-line (nodes) in a file for loading with my game player?

If you can write a code example in C++, Pascal or PHP it is better for me.

spoorcc
  • 2,907
  • 2
  • 21
  • 29
SadeghAlavizadeh
  • 609
  • 3
  • 17
  • 33

2 Answers2

1

You want to do a couple of things:

  1. Figure out what you need to reconstruct a saved node completely enough to use it again.
  2. Prepare all that data you need.
  3. Look into file i/o. There are loads of tutorials online, search for "c++ file i/o" or something similar.
  4. Now you implement file saving/loading.

I'd guess you'll end up with something like this for saving.

write number of nodes
for node in node_list:
    write node info

And then for loading

read number of nodes
for i in range(0, number_of_nodes)
   read node info

If you run into a specific problem ask a new question.

dutt
  • 7,909
  • 11
  • 52
  • 85
  • I think your means about node is Linked list, and I know about that but in this type I can't use them, because the next node is depend on player choice and each node maybe has several next node. My means that how I can store this type of node structure in file. Thanks – SadeghAlavizadeh Feb 11 '14 at 11:05
  • That would go into step 1, figure out what you need to reconstruct a node. Sounds like you need to store the current player state somehow and then all the nodes with ids and links to the ids. – dutt Feb 11 '14 at 12:57
0

I think you should take a look to xml.

There are a lot of libraries to work with it, personally in c++ I prefer pugi but you can take a look to libxml2, xerces, etc...

Pugi XML

If you don't want user interaction you can always encrypt the xml before save it.

Jose Palma
  • 756
  • 6
  • 13
  • yes I know that the XML is a way for store the information in file but I want to know how I can store the structure of nodes and their properties in file via XML. Thanks – SadeghAlavizadeh Feb 11 '14 at 11:08
  • Please take a look of building xml trees here [link](http://stackoverflow.com/questions/17168558/build-an-xml-tree-from-scratch-pugixml-c) – Jose Palma Feb 11 '14 at 12:23