Jump to content
  • Advertisement
Sign in to follow this  
Abdou23

Best way to store text for a Text based game

This topic is 680 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a text adventure game using SWIFT & Xcode, and I found that the best design choice is to separate the text from the logic. The text will be stuff like conversations, descriptions, etc.  But, I'm not sure what is the most efficient way to actually store that text and how to connect it to the classes. Should I use JSON format? If I used plain text files can I link different sections from them to the code?
Any suggestions would be much appreciated.

Edited by Abdou23

Share this post


Link to post
Share on other sites
Advertisement

Depending on how you are going about loading text, either using plist or JSON from a remote load should work.

If you are going the JSON route download SwiftyJSON. It will make your life SOOOOO much easier.

Also you can use the Userdefaults to help with settings and save data for external reading. :)

 

I made a "Choice Your Own Adventure App" that used JSON to download new stories and then stored them as plist.

 

Best idea is to create a template plist and clone it. I have found that it is much easier to handle updates and supporting multiple users on the same device.

Edited by Navyman

Share this post


Link to post
Share on other sites

Depending on how you are going about loading text, either using plist or JSON from a remote load should work.

If you are going the JSON route download SwiftyJSON. It will make your life SOOOOO much easier.

Also you can use the Userdefaults to help with settings and save data for external reading. :)

 

I made a "Choice Your Own Adventure App" that used JSON to download new stories and then stored them as plist.

 

Best idea is to create a template plist and clone it. I have found that it is much easier to handle updates and supporting multiple users on the same device.

Actually what I had in mind was to use the JSON file locally. There is also the text files that Xcode uses for localization but as far as I know there could only be one file per language. Could you tell me more about how plists might be used  with something like this, keeping in mind that there will be a lot of text in the game. 

Share this post


Link to post
Share on other sites

Think of plist as an xml doc. It can store information in crazy and complex ways or be very simple. All depends on how you want to structure the information.

The best part is you can control if something is an array, string or int and Xcode works well with them.

With plist you can make the root an array and use the index value to move around the file.

You can even load the whole file into memory to make actions very fast.

Jigstarapp.com is an app that I have worked on and it uses plist to control images and their related data.

Edited by Navyman

Share this post


Link to post
Share on other sites

Why not streaming your text from a simple file? You could pass your classes just file offsets and seek/read from that offsets the text for each text block. This would also make chaining text blocks together much easier and you could also do it from a package (like zip) without any problems

Share this post


Link to post
Share on other sites

You can just use the standard iOS localisable.strings files.  

The standard API defaults to using the files bundled with your app but, it does have extended functionality to specify different .strings files using a file URL.

Here is an example:

http://iosapplove.com/archive/2013/01/localizable-strings-how-to-load-translations-dynamically-and-use-it-inside-your-iphone-app/

Edited by Buster2000

Share this post


Link to post
Share on other sites

Why not streaming your text from a simple file?

A simple text file is not as good at handling any with a larger index. Because it you changed character counts at point A then forgot to account for this every index offset after that point would be wrong. Using a plist the text can be altered, but maintain the same indexing. 

Share this post


Link to post
Share on other sites

Formatted flat files aren't that bad.  They've been used in Unix systems for five decades or so.

 

And the index isn't much of a problem. A text-based game is likely to only have a few thousand lines of text, maybe ten or twenty thousand in an extreme.  That's maybe a half megabyte of data.  Compared to suggestions of YAML and JSON, the flat file is going to be smaller and likely simpler to parse.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!