Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colossal Caves Adventure - access data source using javascript

I've been playing around with the idea of creating a javascript version of the original Colossal Caves Adventure, as a way to teach myself the language. The original data file for the adventure can be found here -

http://jerz.setonhill.edu/if/crowther/

I'm hoping an experienced javascripter can suggest to me the best way to store and access the text data file (which is only a few hundred lines long). At the moment I'm thinking of embedding the text in a hidden element in the html page and accessing it that way, but I know that lacks elegance. What are your thoughts?

like image 857
Craig Schwarze Avatar asked Jul 27 '26 10:07

Craig Schwarze


1 Answers

You could dive in the deep end and learn AJAX while you're at it. Grabbing content as needed is exactly what AJAX is great at. (If you're learning JS, you will eventually learn AJAX)

If you really want to load all content on page land, I would recommend breaking the content into individual <input type="hidden"s. JavaScript grabs their contents very easily, and you can give them descriptive ids that will make serving the content more intuitive during programming. e.g.

<input type="hidden" name="r121" value="You come upon a fissure" />

Which could mean result r 121 is "You come upon a fissure"

like image 200
Shad Avatar answered Jul 29 '26 22:07

Shad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!