DEV Community

Fran Tufro
Fran Tufro

Posted on • Originally published at onwriting.games on

talking in code: state

yesterday we talked about the concept of variables and their use in narrative.

today I want to focus on the concept of state.

programmers, or at least the older ones like me, tend to think a lot about this.

both a game and any other computer program have states.

if I am writing in a word processor, all the text I wrote is part of the current state of the program.

if I selected an option, for example an italic style in the text, it is also part of the state.

but not only what I wrote, the position of the mouse, which menu is open, whether the file is saved or not, the marks of the spell checker, all this is state.

as a simplification when creating stories:

all the variables that we have at our disposal and their value at a given point in the game are the state of our story.

Enter fullscreen mode Exit fullscreen mode

as in the example of the word processor, this may not be limited to the variables that we create to guide the narrative.

if our game has gameplay elements or resources (for example 'Pieces o' Eight'), we can use the current state of that gameplay variable to define available options in our game:

SHOPKEEPER: The Sword is 100 Pieces o' Eight. The Shovel is 75 Pieces o' Eight.
  * I'll take the Sword
    req pieces_o_eight >99
    -> buy/sword
  * I'll take the Shovel
    req pieces_o_eight >74
    -> buy/shovel
  * I don't have that kind of money.
    req pieces_o_eight <75

Enter fullscreen mode Exit fullscreen mode

in this example, you can see how I limit (using the req command, for require), which options I show : if the user has the money, I show the option to acquire the object, if they don't, I don't show it.

you can (and honestly should ) use this to bring your game to life.

an example would be adding alternative options when the conditions are not met:

* I don't have money for the Sword, but... could I wash the dishes?
  req pieces_o_eight <99

Enter fullscreen mode Exit fullscreen mode

this is what I usually call reacting to the state.

it's vital that at every moment in the game we consider the possible states in which a player can arrive at a line.

think about if there's something interesting that can be done at the narrative level by reacting to the current state.

is there any game that you think is very good at reacting to the state? Hit reply and tell me!

Top comments (0)