Making an Adventure Game - Part 5.
- 3 minutes read - 428 wordsPreviously in this series: Part 1, Part 2, Part 3, Part 4.
So, that’s almost it. There’s just a few more things to do.
The first thing to notice, if you’ve been playing along with the GitHub repo, is that there’s some odd code here and there. It looks like this:
<<click "Would you like to play again?">><<script>>state.restart()<</script>><</click>>So, what’s all that about? Well, it’s not that complicated. The first line just says “The End”. The two single quotes (not double quotes) make the text contained within them bold. You can of course do much more complicated text formatting if you want.
The second line gives the player the line about “Would you like to play again?”. However, you can’t just put a link back to the start here. Well, you could, but your game wouldn’t work properly.
The reason is that the tweego tool automatically includes a library called
“sugarcube2”. This library does an enormous amount of work for you. It’s what
creates the sidebar, enables loading and saving, and much more. One of the
things it does is keep track of the state of the game, including how many turns
you’ve taken. One transition from one passage to another is one turn. For
resetting the game to work, you need to include the code above, which tells the
game engine to reset all of the user state, including the number of turns taken.
The sugarcube2 library is really well documented, and is still being actively developed. The idea is that you can make much more complex games using it than you could if you had to do all the work yourself. I use it for the Tenopia game, so that I can manage inventory and so on. Basically, if you want to make a game with any kind of complexity, you want to use sugarcube2. There are modules for all sorts of add-ons, such as a proper inventory management tool — which I wish I’d known about building the Tenopia game, because I basically reimplemented the bits I needed in script.
Luckily, the tweego tool manages the libraries for you, so you can just build
your game using its features and not worry at all about what this does to the
runtime.
Next time, I’ll look at how you can amp up your game with pictures and fonts, and how you might want to go about doing that.
As always, I read the comments, so if there’s something else you’d like to know about, drop me a comment and I’ll see what I can do.