Writing a computer game is very different from the creative writing you will have been taught at school or university. When writing a novel, for example, the text-to-reader delivery method is so simple that it becomes invisible and we forget about it: the reader generally jumps to the first page of the actual story, then reads each word after the last in the order you put them, and they expect semi-regular breaks. That’s more or less it. The book itself is an inanimate object.
Video games, however, are not inanimate. They have a life of their own and tell your story for you, like an actor performing your words. In order to write a film, a writer often has to give instruction on how a line is acted. Similarly, in order to write a video game, you have to understand at least two absolute basics of how to instruct a computer to tell your story the way you intend.
TOPIC 1: BUCKETS
Indulge me for a second: imagine you’re telling a spooky campfire story to a friend, but you allow them to name the lead character. They choose ‘Deckard’. Worried that you might forget the name, you write it on a piece of paper, then slip that paper into a bucket on the ground near you.
You get a pen and write ‘Protagonist’ on the side of the bucket. Next, in a tense chase sequence, you ask them to decide which object the protagonist grabs: a gun or holy water. They choose ‘holy water’, so you write that on another slip and put that in another bucket, which you scrawl ‘Held Object’ on the side of.
Reaching the end of scene, the villain of the story corners the hero. You check your notes, and the Big Bad’s line reads “Put the (Held Object) down, (Protagonist)!”. This has been a very long story, so you reach into your buckets, check the slips, and say aloud: “Put the holy water down, Deckard!”
Congratulations! You just used a variable. In computing, a variable is like a bucket. It has a tag on the outside to tell you what sort of thing should go inside, and contains a piece of information which you can refer to later. You’ll need to check the requirements of the tool you’re using, but in most computer languages that looks something like this:
> VAR $heldObject = “holy water”
The command above tells the computer “create a new variable called heldObject, and put the phrase ‘holy water’ inside it”. Now, let’s say I later want the computer to read out the sentence “Put the holy water down, Deckard!” for me.
All game writing tools will have a special symbol, for example, ‘$’, which you can use mid-sentence to tell the computer that the next word is a variable name (the tag written on the side of the bucket!), and that the computer should swap it for whatever is inside that variable. So if ‘$’ is our special ‘I’m-talking-to-you-now-computer’ symbol, the line above would read:
> Put the $heldObject down, $protagonist!
Just like in my campfire example, the game would read that as “Put the holy water down, Deckard!”.
Suggested product
Film Stories issue 48 print edition: 168 pages, the UK's biggest film magazine
£6.99
TOPIC 2: CONDITIONS
Let’s keep that imaginary campfire scene rolling. After telling your friend your lightly customised horror tale in which they defeated the villain with their $heldObject, they ask you how that object came to be in the story. But they could have chosen either a gun or the holy water, and these are objects with entirely different histories!
> /If it’s true that/ your friend chose the gun, /then/ you read out a passage about the gun’s last owner. /If it’s true that/ your friend chose the holy water, /then/ you tell them about the villain’s past life as a priest.
Brilliant! You just used two /conditional statements/. This is an instruction to the computer that it should do a certain thing (read the gun-related passage) on the condition that another thing (they chose the gun) is true.
A conditional statement allows us to check what’s inside a variable, then give the computer a varying set of instructions based on the outcome of that check. This is incredibly useful because it allows you to customise your story based on all sorts of things – in this example, a choice that was made quite a while earlier. In simple English, our conditional might look like this:
> if the variable heldObject contains “gun”, then say “The gun used to belong…”
Just like with variables, your tool will have a special symbol to tell the computer that a conditional statement is coming. Here, I’ll use ‘~’. Again, you’ll need to check with the tool you’re using, but generally, in code, it will look like the following:
> ~ if (heldObject is “gun”): “The gun used to belong…”
> ~ if (heldObject is “holy water”): “The villain used to be a…”
The rule here is: if the condition in the brackets is true, write out the thing after the colon. So what the computer understands is that if heldObject contains “gun”, it should show the player the line “The gun used to belong…”, and if heldObject doesn’t contain “gun”, it should do nothing and simply move to the next statement, where it will check if heldObject contains “holy water”, and so on.
YOU’RE READY
These two concepts, the variable and the conditional statement, will allow you to successfully instruct the computer in how to tell your story. You can use it to craft grand narratives where later chapters reflect decisions made early on, or simply to let a player name their character ‘CAPTAIN BUTTCHEEKS’, as they so love to do.
You can use variables to track what inventory items a player has accumulated in your story, and use conditionals to open new pathways based on those possessions.
They’re super-easy to use, so get on inklewriter, Twine, Yarn Spinner, or my Fungus and start writing!