Hey all. My name's Ben, and I'm a programmer. I wrote my own JS text-adventure engine, and I thought it would be cool to share how some of it works.
The parser takes input from a plain old regular HTML input box, but the page is styled so it looks like an old school command line. When the player presses enter, the text in the text box is sent to a parser for processing. There are actually like 8 different separate parsers controlled by game statuses. The game processes input differently depending what status it's on, so if
status==8 for example, the game knows it's in combat mode and will send received inputs to parseCombat instead of parseInput.
The important parser is parseInput, which handles primary dungeon navigation (ie, 'look around', 'take object', 'talk to orc', etc). It works like this:
That's the long and short of primary dungeon navigation. Not actually that complicated when you get down to it, but certainly took a while to write. The whole game takes up about 8000 lines of code, give or take. Always makes me chuckle to think that my engine (written between 2015 and now) is only just getting close to the power of Zork's (which came out in 1977 :p ).
Hope that was somewhat interesting. You can see the engine in action in my game Underground Dungeon. I'll be posting some massive bug fixes and engine improvements in the next couple days.
I've given your game a try and the parser works fine.
If it doesn't get the commands entered it makes clear why it doesn't. Great job!
One thing though, it doesn't understand 'restart'?
Game is here: https://textadventures.co.uk/games/view/gfeokxwhhkacym2c6njupq/underground-dungeon
My only feedback is that your choices for verbs differ from the conventions used in other text adventure games:
The standard shortcut abbreviation for "look" in TA games (the general "see what's in the room") is "l". And the shortcut for "examine" (or "look at") is "x". You seem to have those reversed. You have "x" on its own mapping to "look", whereas "l" is mapped to "examine" (or "look at"). While it's up to you how you map your commands, I'd recommend sticking with what people know from decades of game playing. :)
Nice work, in general!
@Jay Nabonne - Thank you for the pointers! I don't know why, but at the time I was under the impression "===" was for comparing disparate data types (which makes no sense), so that's something I need to correct. The parsers I'm used to are very oldschool and haven't had 'x' 'i' etc. I'll fix that when I get a chance.
@Ewald - I'll add a restart command, thanks for the recommendation!