Hey, I'm Benji! I made this engine. And I made this forum just now! If you have any questions, please ask here and I'll be happy to help.
A JavaScript text adventure game engine · By
No worries at all! If you're interested, I'd encourage you to check out at how the sound was implemented for the demo here: https://github.com/okaybenji/text-engine/blob/itch/custom/audio.js
It's pretty straightforward, so definitely take a look if you're wanting to do something similar. I can help with this to some extent, so just let me know if you have any questions about it.
Sorry to bother you again. Is there a command to add or remove dialogue options? The readme mentions a "removedOnRead" option, and theres also the prerequisite option, but I'm not sure how actually implement them in the code since there doesn't appear to be an example in the demo-disk (unless there is and I'm just blind or something, at which point I apologize). The prerequisite option also seems to be for having one dialogue lead to another, rather than an external action of line adding it later. What I'm referring to is, say, theres a locked door or something, you shouldn't be able discuss the locked door with an npc until after you've actually discover that it's locked.
It's no bother at all! I'm happy to help. You can use the prereqs to do this. You can make up any arbitrary string as a prerequisite, for instance 'door', and place it on the line you wish to hide, like this:
{ option: 'How do I UNLOCK this door?', line: 'You have to use a key, of course!', prereqs: ['door'] }
Now the option won't show up until some code runs that pushes that prerequisite onto the character's chatLog. You could do this, for instance, in the onLook callback for the door like this:
{
name: 'door',
desc: 'It\'s locked.',
onLook: () => {
const npc = getCharacter('gregory');
npc.chatLog.push('door');
}
}
Now you've met the prerequisite for discussing the door with Gregory (or whatever your NPC's name is). The next time you talk to him, the topic will show up.
This technique is used in the "ur dead" demo. After you learn from the character Fran about how names work in the underworld, it unlocks the ability to ask the other characters you've met what their names are.
If you have more questions, don't hesitate to ask. Like I said, happy to help!
Oh, ok. Thanks. That worked. I'm pretty bad at programming, so wrapping my head around where and how to actually use the functions without just crashing the program is doing me in.
I have one more question. Using the method for sound you posted earlier, is there a way to get a sound to play when a room loads. I've gotten sound to play for the keyboard like you used for the demo, but I can't figure out how I'd get it to play when a room loads. I discovered by accident that putting it under "onLook" work, but that's only for when the player issues the look command for the room (which is actually kind of cool and I will end up using, but isn't what I need.)
hi there benji! i came across this engine while looking for minimalist 2D engines to study to base my own engine on, and i have to say i really like the idea of a text based engine, usually text based CYOA games are just handwritten in people's language of choice from scratch, so the idea of a text based game engine is really cool! could you talk a bit about how you came up with the idea and how you went about implementing the engine? thanks :D
Hey, sorry for the delayed response! I guess you're right that text games are often written from scratch. Even in my case, I had an idea for a text game I wanted to make before I started writing the engine. But, I thought it would be both beneficial and also fun to structure the code such that it could be used for other games.
Having an idea in mind for a game was really useful for developing the engine, because it gave me a clear picture of the features I would need to implement. You can see this from the very first commit on Github, which included very simple versions of an engine and a game disk to then be expanded upon.
Later, when working on the new features for what would become text-engine 2.0, again I was working in parallel, this time on three new game disks. One of these was what would become the new demo disk for introducing folks to the game, and another was a new story disk I was collaborating on with a friend. Once again, fleshing out those games gave clear direction for which new features to implement next.
Hi Benji, this is a fantastic tool, really having fun learning and making a game with it.
I had a question about how to implement a music file that starts 5 seconds after the startup and loops. I understand the files and folders needed, but I'm stuck as to what to put in the audio.js file to accomplish this. I'm still a beginner at Javascript, so any help you could provide would be brilliant!
Hey, thanks! Happy to help.
If you just want a looping audio file to play five seconds after the page loads, you probably don't need to interface with text-engine at all to do that. I would just add something like this in the script tag of your HTML (or a separate script file if you have more custom code you want to add):
const audio = new Audio('audio_file.mp3'); audio.loop = true; setTimeout(() => { audio.play(); }, 5000);
But if you want it to start 5 seconds after some particular event in the game, such as when the player enters a room, you could put the timeout in e.g. an `onEnter` function or etc. on your disk.
Hope this helps! If you need more help with this let me know.