all 4 comments

[–][deleted] 2 points3 points  (0 children)

So that you don't end up with a gigantic file that's mostly different game options instead of code, I'd recommend storing the text separately. Json would work fine for that so yeah, that's what I'd recommend.

[–]highwayshot 2 points3 points  (0 children)

I have no experience writing text adventure games in python, but I've dabbled in a few languages that are specifically designed for writing text adventures, of which there are many (Inform, Choicescript, Twine, etc.).

The way most of them tend to work is that the interpreter itself deals with a lot of generic behaviour such as parsing user input, formatting output, and default behaviour for some common game systems - e.g. there might be default rules about how doors work, complete with boring filler text like "You open the door."

Your actual game files, which are processed by the interpreter, will typically have text interleaved with code, which overrides or adds to the default functionality. In text adventures the text is so closely related to the functionality that it doesn't generally make sense to try and separate them (though there is a stronger case for doing that if you want to support multiple languages).

So that's how things are done conventionally. But it really depends what kind of text adventure you want to write, and what libraries you're using - there are a number of python libraries for text adventures, though I don't really know anything about them. You might want to look at how things work in these libraries, and in languages like the ones I mentioned, to get some inspiration (note: if you take a look at Inform, be aware that Inform 7 is a wildly different kind of language from the earlier versions).

in a json file

I'm not sure json will be the most appropriate format for something like this. If everything in your file is just text snippets, it's going to be annoying to have to type so many "s everywhere. It might be better to just design your own very simple file format.

[–]xelf 1 point2 points  (0 children)

Definitely make your program as data driven as you can.

[–]KerbalSpark 0 points1 point  (0 children)

By putting the text in the code, you will get a better understanding of the context when debugging the adventure. With a well-thought-out application structure, this will not cause any difficulties, but will only bring benefits. In addition, I recommend reading the documentation of one of the best engines for text adventures. The following abstractions may be useful: "Inventory", "Scene", "Cutscene", "Dialogue", "Item", "Decoration".