Is there a difference between storing data in your program or a document file?

Viewed 85

I'm developing a text based game and was wondering if there will be any issues if I were to just write all the text in the code instead of making something like a csv file to read the data from. It won't be as organised, but I was wondering if the game would take more memory or have worse performance if I were to put the game in code instead of a text document or csv file.

1 Answers

Some advantages and disadvantages:

In-a-file

  • Easy to modify, easy to localize
  • Not very secure, anyone can look at it and hack it
  • Has to be parsed at runtime, what to do about errors if badly formed?
  • Tiny performance hit on load (probably not worth worrying about)

In an embedded resource

  • No separate file lying on the hard drive for your users to examine and hack (easily)
  • Can localize fairly easily

In-code

  • No need to parse the input file, syntax and structure is checked at compile time
  • Can define your game resources using strongly-typed values, e.g. Room cave = new Room("Cave", "Long description ...").
  • Can define more complex relationships between objects without resorting to string-id references between them. cave.ConnectsTo(passageway), cave.Contains(sword), ...

In terms of memory consumption it's a wash - the strings will be in memory in either case - unless you are writing a huge game in which case a database would be more appropriate with the ability to easily load individual areas of the map and eject ones no longer needed from memory.

Related