Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

[Twine 2.1.1][SugarCube 2.14][JS] Reading external JSON files and file names

$
0
0
Hey there,

I'm researching some way of reading files in the folder where my twine story is. I'm interested in reading my /images and /templates folders. Since my project will probably grow pretty large in time and I have no idea how to organize all the data (images of potraits, landscapes, characters, maps, etc.) that I'll be using in my game inside the Twine editor, I want to be able to extend my game through external files.

I would want to put images of my items, portraits of characters and landscapes into my /images folder and then .json templates into my /templates folder. Both folders would have their own subfolders.

I would like to specify the data such as properties of my game objects inside the .json file and then assign random image paths from the corresponding images folder to the object, then use 'new' and prototype inheritance to generate game objects when my twine game starts.

Example:
/images/Enemies/Goblins/Portraits holds the following files: GoblinPortrait1.jpg, GoblinPortrait2.jpg, GoblinPortrait3.jpg
/images/Enemies/Goblins/Characters holds the following files: GoblinStand1.jpg, GoblinStand2.jpg
/templates/Enemies/Goblins holds Goblin.json, GoblinSoldier.json, GoblinMaster.json, GoblinWorker.json

I would build a list of GoblinPortraits and another list for the GoblinStand images and then randomly assign the paths to these images to my Goblin enemy game objects. The properties of the Goblin enemy game object would be read from the .json file and then when needed instantiated using the new operator.

I'm very new to web development, but I'm very eager to learn and experiment.
My question is, is this possible locally on the users computer or do I have to host these files somewhere on the web? What are the possible solutions to this problem considering that I use Twine 2, SugarCube 2.14 and JavaScript?

I read that, I'd need JQuery to deserialize the templates of my game data, but I find no clear solution to reading filenames of a folder using JavaScript. It seems I'd need to setup Node.js or something to be able to read the file names, but that would turn my game into a server client... eh, it seems too much compared to the benefits that I'd gain from going through setting it up let alone getting it to run.

Viewing all articles
Browse latest Browse all 1844

Trending Articles