0 votes
by (310 points)
edited by

Building a game rather than a story and I want to allow allow interested players to create custom versions of some of my encounters, to that end I am thinking best way to do that is to have the game read a human readable file like .txt to make it as easy for the players as possible and have the variables read into a series of arrays.

 

An example of this would be

Twine File Variables

$EncounterName[0]
$RandomEncounterTrigerValue[0]
$VariableGoverningWhichPassage[0]
$Condition1Text[0]
$Condition2Text[0]
$Condition3Text[0]


and then have the file read something like

<File Opener>

$EncounterName = Friend
$RandomEncounterTrigerValue = 1

$Condition1Text = Long String of text
$Condition2Text = Long String of text
$Condition3Text = Long String of text

<end encounter>

$EncounterName = Stranger
$RandomEncounterTrigerValue = 2

$Condition1Text = Long String of text
$Condition2Text = Long String of text
$Condition3Text = Long String of text

<end encounter>

etc

<end file marker>

But I cant find how to load the file to parse the information to the variables.  Also would I be better loading the whole thing into the game or just select variables and loading the big stuff just for the passage when it needs to be displayed?

1 Answer

+1 vote
by (159k points)
selected by
 
Best answer

Please don't include information about either the Twine Compiler or the Story Format you are using within the Question Title, it just makes that title longer that necessary and serves no real purpose if you have used the Question Tags to state this information, as you have done.
(although knowing the full story format version can help as that can effect answers).

Based on the fact you stated "I want to allow allow interested players to create custom versions of some of my encounters" I am going to assume that your game is not going to be hosted on a web-server.

Unfortunately web-browser's are very restrictive (for security purposes) when it comes to accessing locally stored files, excluding the standard file types that a HTML file normally references. There are a number of techniques you can use to try and get around these restrictions but none of them work for all web-browsers.

This GitHub Gist page lists two of them along with links to further information about those techniques.

A more experienced Javascript coder would be able to give you better advice but normally the HTML file would either contain a pre-existing script element reference to the external (JSON) file storing the relevant data you want to load, or it would use Javascript to to dynamically create said script reference based on pre-existing file name information.

by (310 points)
Annoying but not a lot to be done about it, thanks for the answer Greyelf
...