Jump to content
  • Advertisement

chocolate_outline

Member
  • Content Count

    1
  • Joined

  • Last visited

Community Reputation

1 Neutral

About chocolate_outline

  • Rank
    Newbie

Personal Information

  • Interests
    Programming
  1. Hi, I think the solution you are looking for is scripting. Each object in a room has an associated script, which is just a plain text file. The behaviour for every item in the game can be unique and as simple or complex as you like. Back in the day, a lot of text adventures were written in BASIC, so you're trying to do is probably a lot harder. (some of them are even open source https://github.com/SinclairQL/akalabeth ) So you could use BASIC, Lua or Python but you will get annoyed trying to create bindings, so if you're feeling ambitious you can create your own scripting language. Here is an example of a script for the box with a push button @Push: // used the Push command GetFlag FOUND_BUTTON End // if flag FOUND_BUTTON is 0 goto label End Print "You pushed the button." Wait 3.0 SoundEffect BUZZSAW_1 Print "A mechanical arm bursts out of the box and tries to decapitate you!" Goto End @Turn: Print "You turned over the box..." Wait 0.5 SoundEffect MYSTERY_1 Print "You were surprised to find a big red push button underneath!" SetFlag FOUND_BUTTON Goto End @Inspect: Print "It's a small wooden box, varnished mahogany." Goto End @Shake: SoundEffect RATTLE_1 Print "It feels weighty. It seems to rattle when you shake it, as if it contains moving mechanical parts." Goto End End: // finish executing the script I've not written a text adventure game before but I think this might be a good way to do it. The way it would work is, when the user enters a command it would look for the label in the script and execute that bit of code. I put '@' before the command labels to distinguish them from normal labels, like the End label. When you compile the script you would have to export a table which maps the command names to line numbers so that when the user enters a command you can jump in at the right place. Anyway, I'm sure you could come up with a neater scripting syntax (I don't like how every command has to end in 'Goto End'...). The point is you can come up with your own design that is specialised for doing exactly what you want. The cool thing about scripting is the script could define it's own commands, so you could get really imaginative with how the user can interact with something. By using flags (like the FOUND_BUTTON flag) you can affect the global state of the game, you should be able to read these same flags from other scripts so that they can 'communicate' with each other. You can also see how I've added timing cues and sound effects to the script, this is how you add life to your game and make it entertaining. If you've ever played a JRPG you can get an idea of the surprising level of detail you can go into with just text. If you want your text adventure to be super optimised here is a helpful article about using writing a bytecode interpreter for games http://gameprogrammingpatterns.com/bytecode.html That article in particular dives into making a tree parser which you don't really need to do, all you need is a few commands which can accept float, int or string literal parameters.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!