I'm creating a single player web RPG. I was originally storing NPC dialog in a JS object. I could cycle through lengthy dialog in an array as I wanted. I can also store objects with K:V pairs.

That being said, is it easier/faster to manage, store and retrieve dialog in the following three methods:

Also, can you tell me why one is better over another for running a single player web rpg:

a JS Object:

var dialog = {
    quests : {
        quest1 : {  
            NPCName: {      
                "Task 1 - Introductions" :
                    "dialog" :
                        "I'm Pedro",
                        "Welcome to my neighborhood",
                    "wordBank" :
                        "Hola" : "Hello",
                        "Como" : "What",         

In pure JSON:

"quests" : {
    "quest1" : {    
        "Lee" : {
            "Introductions" :
                "this" :
                "that" :

Or in a database:

enter image description here


The content creation perspective:

RPGs tend to be quite text-heavy so you and your team will spend quite a lot of man-hours writing, proof-reading and maybe even translating the dialogs. It might pay off to make this process as comfortable as possible.

Pure Javascript objects have the advantage that you can more easily integrate functions into your dialog system than with JSON. Also, the syntax is a bit more lax than with pure JSON. Otherwise there isn't much of a difference between the two approaches.

Having the dialog options in a database could be more manageable when you plan to write a specialized GUI tool to create and edit the dialog trees (When your project is going to be very large, this might pay off after all). But when you plan to enter and edit your dialog directly in the database with a general-purpose SQL management tool or even worse typing out SQL queries, you will have quite a hard time ahead of you.

The performance perspective:

Storing the dialogs client-sided could be quite a lot of data which - in the worst case - might have to be loaded all at once when the application starts. That could take a few seconds and also quite a lot of bandwidth.

When you store it on the server, the dialog options will be loaded on demand. That means shorter load-time, but worse responsiveness during the dialogs. A simple tradeoff you have to decide for yourself.

Keep in mind that you can also store your dialog as JSON and store it on the server. You can have the client request individual JSON files on demand with XmlHttpRequest.

The piracy perspective:

When your game runs completely in the web browser without having to rely on any server-sided components, it is trivially easy to pirate. Someone who wants to plagiarize your game just needs to download all the files referred to in the HTML, rebrand it and put it on their own webserver. But when you keep some of your content server-sided, it becomes far more difficult to rip it all.

| improve this answer | |
  • \$\begingroup\$ Thank you. From a piracy perspective, if I store my dialog in .json files and load on demand/as needed (ie: talking to NPC1, load NPC1 dialog), do people still have client-side access to the text? I thought that only happens if I put everything in a JS object and load. I guess there's no difference. \$\endgroup\$ – Growler May 15 '14 at 12:34
  • \$\begingroup\$ @Growler That depends on how your server manages the .json files. Try to open the URL of the files in your web browser. Chances are your server will deliver them even though you aren't even playing right now. When you want the client to only be able to get the JSON of the dialog they are currently in, you will have to do some server-sided coding and create a dialog webservice with session handling. \$\endgroup\$ – Philipp May 15 '14 at 12:55
  • \$\begingroup\$ @Growler When your game decides to load NPC1 text they will have access to it. It would be more difficult because they would have to talk to all of the NPCs to get all of the dialog. To do that in an automated fashion would be harder than just downloading a single file but not hard. \$\endgroup\$ – stonemetal May 15 '14 at 17:19

This is a very low level implementation detail, given there are very loose requirements for this kind of stuff (loaded once during game startup, only the game needs to parse it, it's plaintext so very little data). The default answer for this is whatever you / your team are most comfortable with.

Having said that, I'd consider JSON a little bit better:

  • It's extensible
  • Doesn't need a DBMS to view/edit

Furthermore, the advantages of database don't apply here:

  • You don't need to perform queries/joins, everything is loaded during startup into your game directly
  • You don't need to modify this data during gameplay, let alone having performance or ACID requirements

The differences between JS object and JSON file are moot as you can go from one to the other using getJSON().

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.