Is there a developed IF authoring system that enables use of state machines?

I have been struggling against Twine because I want to create a game where you can move freely through the map as well as making several text choices in each scene. I’m not interested in something like Unity or Godot because the game is text-based (plus I don’t understand Unity/Godot). Twine isn’t a great fit.

I was thinking of making my own authoring system using state machines, behavior trees, and dialogue trees myself but I have heard that you have to choose between finishing your game or your game engine if you work on both at the same time. If there’s no time to do both, I would prefer to finish the game I’m working on.

I really want to write something that is game-like. I’m inspired by writers like Ocean Vuong and Elle Nash but I’m also inspired by game designers like Kate Compton.

I have the programming knowledge to write my own engine, but the time invested might not be worth it. I used Narrat to make a an old demo and I really liked it, more than even Twine or RenPy, but it is still hard to customize.

1 Like

Do you want a visual representation of state / behavior trees? Or a textual language describing them as markup or source code? Or are you fine with either?

(Some people care, some people don’t see a difference, gotta ask…)

I would prefer both, but I would take text only.

I’m hoping I’ve found a way to cheat this: I’m developing an authoring system (Bedquilt), and I’m developing some games, but I’m not using my own authoring system to develop the games. I’m thinking “in Bedquilt” as I plan things out, but then using other systems for the actual implementation and forcing my way through whatever limitations and pain points I encounter. This way I can apply what I learn from that to make Bedquilt a better system, while also avoiding imposing “Sapir-Whorf” limitations on my creativity. I think developers of all kinds of software have a tendency to forbid themselves from thinking about things that they know will be painful to express with the tools they’re familiar with, and this approach will help me prevent doing that.

1 Like

A state machine is a coding problem, so you can implement a state machine with practically all IF languages, parser or choice, at least IMVHO.

Or there’s a more specific issue I don’t have noticed ?

Best regards from Italy,

Personally, I would suggest dendry (but I’m biased as I helped to develop it). It doesn’t have explicit representations of state machines, but I think it’s easier to develop game-y mechanics in dendry as opposed to twine. Smwhr’s tutorial might be helpful. Here’s an alternate template that has editable CSS.

3 Likes

Ink has a data structure “list” (not really a list) that is intended for creating simple state machines (or, at least, that’s the use case that they introduce in the documentation). But more generally, Ink is a good choice for customizability, whether you want to do “mostly IF” with some bonus functionality in JS, or whether you want to write the entire game primarily in some other language/engine and then just use Ink for the choice-based-IF-stuff that happens in each room.

2 Likes

Definitely! It was relatively easy for me to develop my most game-y IF so far… And when I look at stats on itch, it is my most popular game (not quite what I expected actually. I guess a bit more game-y stuff does not hurt…)

1 Like

Have you consider using Inform 7 for a project like this?

I’ve heard and read about state machines over the years but never investigated their workings in any depth. After reading the wikipedia page I quickly asked ChatGPT the following question - “How would you program a finite state machine in Inform 7?”. It came back with this code.

ChatGPT Code Example
"Finite State Machine Example" by User

The Lab is a room. The Hallway is north of the Lab. A locked door is north of the Lab and south of the Hallway.

The locked door can be locked, unlocked, or open. The locked door is locked.

Instead of going through the locked door:
    if the locked door is locked:
        say "The door is locked.";
    otherwise if the locked door is unlocked:
        now the locked door is open;
        say "You open the door and pass through.";
        continue the action;
    otherwise if the locked door is open:
        say "You walk through the open door.";
        continue the action.

The brass key is in the Lab.

Instead of unlocking the locked door with the brass key:
    if the player carries the brass key:
        now the locked door is unlocked;
        say "You unlock the door with the brass key.";
    otherwise:
        say "You don't have the key!";

Instead of locking the locked door with the brass key:
    if the player carries the brass key:
        now the locked door is locked;
        say "You lock the door with the brass key.";
    otherwise:
        say "You don't have the key!";

With the same prompt, Claude returns similar code.

Claude Code Example
"Finite State Machine Example" by "Claude"

A state is a kind of value.
The states are idle, alert, pursuing, and attacking.

A creature has a state. A creature is usually idle.

Current state is a state that varies.
Current state is idle.

To transition to (new state - a state):
	now the current state is new state;
	say "State changed to [current state].".

To check state transitions:
	if the current state is:
		-- idle:
			if player is visible:
				transition to alert;
		-- alert:
			if the player is nearby:
				transition to pursuing;
			otherwise if the player is not visible:
				transition to idle;
		-- pursuing:
			if the player is not visible:
				transition to alert;
			otherwise if the player is adjacent:
				transition to attacking;
		-- attacking:
			if the player is not adjacent:
				transition to pursuing;
			otherwise if the player is not visible:
				transition to alert.

To execute state behavior:
	if the current state is:
		-- idle:
			say "The creature wanders aimlessly.";
		-- alert:
			say "The creature looks around suspiciously.";
		-- pursuing:
			say "The creature chases after you!";
		-- attacking:
			say "The creature attacks!".

Every turn:
	check state transitions;
	execute state behavior.

[Helper predicates for state transitions]
Definition: a person is visible if it can be touched by the player.
Definition: a person is nearby if it is within 3 spaces of the player.
Definition: a person is adjacent if it is within 1 space of the player.

[Example room and creature setup]
Lab is a room. "A sterile laboratory environment."

The test creature is a creature in Lab.

Note:

  • I have not vetted either code sample to see if they compile or function as desired
  • I am not advocating the use of LLMs alone to write code (I wanted to quickly investigate the possibilities)

If may be that you haven’t considered Inform 7 because it is parser-based out-of-the-box, and you want to stick with choice-based tools, but I have read about I7 extensions that allow choices from an onscreen menu or numbered list such as Hybrid Choices by AW Freyr or Inquiry by Zed Lopez (I have never used either of them and there maybe be others out there that I am not aware of).

Is there a reason Dialog’s choice mode doesn’t do exactly what you’re after?

2 Likes

Maybe time to give Balladeer a try?
It’s a modern Python framework, whose world model is all Entities and States.

You can implement your own state machines easily, but there is one included called Fruition which is applicable to many situations.

The development paradigm is text-based. You are mostly either coding in Python, or writing dialogue in a format called SpeechMark.

Be warned, this code will not work. In the first one, “a locked door” creates an object of the “door” kind with the “locked” property, not a generic thing with the name “locked door”. In the second one, it sometimes tries to use “state” as a property of a creature and sometimes as a global variable; it defines “visible” (something the standard library already defines!) in terms of the player, and in terms of touchability instead of visibility, but then tries to check if the player is visible, which will always be true.

I would not recommend using either of these examples as a starting point. Better to start building from nothing than from a defective foundation.

Seconding this! Dialog’s choice mode is literally just a finite state machine. (Though if you want to embed a finite state machine in your game, rather than having the machine be your game, that may not be suitable.)

I’ve confirmed that neither the ChatGPT or Claude example code will compile in Inform 7. So it goes…

So I did look into creating a state machine within Twine. I suppose my problem is the depth to which I want the state machines to control what happens within the game. It might be possible in Twine, but it would be painful.

I think what you’re referring to is using a bunch of if statements to determine which options show up to the player? I wanted to actually use a state machine library.

The documentation is sparse, which I was trying to avoid. That’s why I included “developed” in the title of this post. It does look interesting. I want to use something where I don’t go through the pain of debugging something that is documented poorly.

This could be helpful. Would you mind sharing the link to the state machine example?

This very much could be of great use to someone else. The main reason I stopped using RenPy is because I do not like Python. I much prefer the web platform.

What’s the difference between the game being a state machine and having a state machine in the game?

I was thinking of this section on “advanced state tracking”, although I don’t know whether it’s really what you’re looking for.

1 Like