I realize that few of you “know” me (in case you don’t, I came in #70 in the 2021 IFComp ), but I’ve now put over a thousand hours into various IF games that I’ve created, and I thought it might be helpful to others if I shared some lessons that I’ve learned along the way.
This series will focus on ChoiceScript (CS) syntax, but it is my belief that many of the concepts and principles apply equally well to other languages/tools.
I’ll start off by declaring right up front that I am not a very skilled coder. About the only language I ever “learned” was some basic HTML for designing Geocities pages back in the day, but nonetheless, it’s hard to make much progress in IF these days without an elementary grasp of how computers think. That being said, there are assuredly more elegant and better ways to do every single thing I will be discussing.
This is going to be a continuing series, so if you find it interesting, please feel free to start Watching this thread and/or adding your own contributions.
MOVE_COUNTER
And now for Lesson #1: move_counter
Even if I have no idea what I’ll do with it ahead of time, I now start all new projects by creating a numeric variable called move_counter
which tracks how many steps or “moves” the user makes in the course of playing a game.
*create move_counter 0
If a game consists of exploring “rooms” in a house, for example, then moving between rooms would increment the move_counter
variable by one. This gives you (the designer) a rough approximation of how long the player has been playing.
Now, what can you do with this move_counter
? Well, a lot:
- As a stand-alone achievement - Any player who invests enough time and energy to get to 100 or even 1000 “moves” in your game certainly deserves to be rewarded for their dedication!
- Timed triggers - If the player activates a bomb, you can trigger it to explode in n number of moves, for instance. Or, if an NPC says “I’ll be right back with that ancient map you need to get into the Pharoah’s tomb,” you can use the variable to set a trigger for when they return.
- Timed movements - Maybe guards switch up their routines every n number of moves, or a store closes/opens, etc. Or maybe a bear only comes out of its den at certain times.
- Timed gates - Maybe you want players to solve a puzzle to proceed, but in case it’s too hard or difficult, you can have the gate automatically open after n number of moves. Or, vice versa, you can have a gate close after a certain number of moves.
- Timed payouts - Maybe the player starts a farm or business or trading colony and needs to come back to collect the income. Or maybe the player gets paid a salary every week/month.
- Timed destruction - Perhaps that loaf of bread or pail of milk will spoil after n number of moves. Or maybe an injured NPC will die after a certain number of moves if they don’t get to a doctor.
Obviously, the possibilities are endless, so code in your *set move_counter +1
lines right from the beginning as you write your game so that you can easily add timed special events later on.
It’s important to note that when using move_counter
as a trigger that you mesh it correctly with a second counter variable.
For instance, let’s pretend that a villainous NPC has planted a bomb and informed the player that it will go off in 10 “minutes” (moves).
"Ha, ha! I've set the bomb to get off in ten minutes, you naive fool. Better run for your life!" says Mr. Misunderstood.
The code that explodes the bomb:
*if move_counter >= bomb_counter
*goto bomb_explodes
But what state is the variable bomb_counter
in before the villain activates it? Normally, my instinct would have been to:
*create bomb_counter 0
But since the move_counter
will always be larger than zero, this results in the bomb exploding non-stop, which isn’t what we want Therefore, I set it up like this:
*create bomb_counter 9999999
And because of that, we need to add one more line of code for when the bomb does explode to reset the bomb_counter
variable:
*if move_counter >= bomb_counter
*set bomb_counter 9999999
*goto bomb_explodes
Now, going back to when the villain sets off the bomb, we have something like this:
"Ha, ha! I've set the bomb to get off in ten minutes, you naive fool. Better run for your life!" says Mr. Misunderstood.
*set bomb_counter (move_counter + 10)
Much more to come