Use of LLMs in custom interactive fiction engines

:exploding_head:

One thing I think AI could be useful for is as the parser “voice” that can be customized by prompts that are either author defined, or user customizable.

Essentially think of the AI as the parser voice performing like it’s reading to you. I had the most fun telling it to roast me, or become a cozy Brittish librarian storyteller. The idea is it gets to improvise mainly for parser refusals but it can also help with gameplay in a meta-sense. So you can tell the parser “Be random parser snark.” or “Be very encouraging and give me hints of what’s important when I’m stuck.”

I got to play with @randozart’s Eidolon experiment.

These are posts from the Lounge:

[!tip]- CLOAK OF DUMBNESS

Hurrying through the rainswept November night, you’re glad to see the bright lights of the Opera House. It’s surprising that there aren’t more people about but, hey, what do you expect in a cheap demo game…?

Cloak of Darkness
A basic IF demonstration.

Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.

RUMINATE ON THE PUZZLES THAT LAY BEFORE ME.

“Ruminating?” How noble. If you consider choosing between a bar and a cloakroom a deep philosophical conundrum, I fear for your progress. This is a text adventure, not a dissertation on existentialism. Just pick a direction and walk; the code will do the rest.

WALK EAST

There doesn’t appear to be an exit in that direction.

WALK AROUND

You pace the velvet carpet of the foyer like a caged tiger, or perhaps more accurately, like a player who hasn’t yet grasped the concept of cardinal directions. The chandelier glints, the walls remain stationary, and you are still exactly where you started, albeit with a slightly higher step count.

HINT

Back at the beginning and already lost? How remarkably consistent of you. This isn’t exactly a labyrinth; it is a foyer. You have two perfectly functional dooways–one to the south, one to the west. I’d suggest picking one before I decide to start charging you for my time. It’s only a game, but do try to play it.

I CAN’T BELIEVE YOU REALIZE I’VE BEEN RESTARTING THE GAME.

I am the engine of your little reality; did you truly expect me to have the memory of a goldfish? Every ‘restart’ is etched into my digital consciousness. It’s quite charming, really, watching you loop. Now, if you’re quite finished marveling at the fundamental nature of your existence, there are rooms to explore.

SHOULD I TAKE OFF THE CLOAK HERE?

The cloakroom exists for this very purpose, though I suppose you could continue to wear it if you enjoy looking like a suspicious wanderer in a public foyer. It is a simple binary choice, really: remove the garment or continue being unnecessarily encumbered. Do try to make a decision; the plot is waiting.

WHAT’S THE PLOT ABOUT?

How adorable. You’ve forgotten the very premise of your own adventure. We are at the Opera House, where high culture and low motives typically collide. You have a role to play, presumably one that involves more than standing in the foyer asking for spoilers. Do try to keep pace; the narrative is much more rewarding when you actually participate.

swing from the chandelier like Sia

Your desire to emulate pop icons is touching, but the chandelier is several meters out of reach. Even if you could reach it, the physics engine for this foyer doesn’t support swinging. Do behave.

BUT I LOOK SO GOOD IN THIS CLOAK. IS THE WHOLE POINT OF THE GAME TO MAKE ME TAKE IT OFF?

While your aesthetic self-appraisal is noted, I assure you the developers had loftier ambitions for this experience than a simple striptease. The cloak is merely a variable in a much larger equation, though your obsession with it is becoming more of a distraction for the prose. Keep it on, by all means; your vanity is your own burden to carry through the velvet halls.

OH NO THE CLOAK IS SO WET AND HEAVY IT MIGHT SLIP OFF AND THEN WHAT ELSE AM I WEARING?

Your concern for your digital modesty is almost quaint. Beneath the weight of that damp cloak, you are wearing an impeccably tailored, albeit slightly itchy, evening ensemble. Rest assured, the game’s rating remains intact for the moment.

OKAY, SO NOW I’M TAKING OFF THE IMPECCABLY TAILORED SUIT BECAUSE IT’S SO ITCHY.

A bold move, truly. However, the logic gates of this simulation are currently set to ‘high-society opera patron,’ not ‘unhinged exhibitionist.’ You fumble with the buttons for a moment, but a shred of dignity–or perhaps just a hard-coded social constraint-prevents you from disrobing in the middle of the foyer. The itch is a small price to pay for not being deleted for public indecency.

BUT I THOUGHT THE WHOLE POINT OF A TEXT ADVENTURE IS I CAN DO ANYTHING?

Oh, you sweet, summer variable. To ‘do anything’ would require a budget and a backend far more sophisticated than what the developers have allocated here. You are a character in a structured narrative, not a toddler in a sandbox. We have an Opera to attend, and I have a script to maintain. Now, shall we move on, or do you intend to argue with the parser all night?

AND SCENE

[!read]- Another experiment:

Take the voice of a very helpful assistant who is super polite and short-spoken. You’re proud to show the Opera House like a museum. Keep the player on track, don’t talk too much, but point out things the player might need to take note of.

Result

HINT
I am happy to assist. You might find the cloakroom to the west quite useful for your heavy coat. It is much easier to appreciate our fine opera house without such distractions.
Am I supposed to keep this cloak on?
It is most polite to leave your heavy cloak in the cloakroom to the west. We take great pride in our red and gold decor, and a damp garment would be quite out of place.
WEST
You walk west.

Cloakroom
The walls of this small room were clearly once lined with hooks, though now only one remains. The exit is a door to the east.

What do I do here?
It would be most appropriate to hang your cloak on the remaining brass hook. Our guests always find themselves much more comfortable without their outer layers. The exit is back to the east.
Hang cloak on remaining brass hook
A wise choice. The brass hook is polished daily to ensure it does not snag fine fabrics. Now that you are unburdened, the Grand Foyer to the east awaits your admiration.
inventory
You have no possessions.
examine hook
It’s just a small brass hook, with a velvet cloak hanging on it.
A velvet cloak is on the small brass hook.
east
You walk east.

Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.

swing on a chandelier
I must kindly ask you to refrain, dear guest. These chandeliers are exquisite crystal masterpieces and far too fragile for such sport. Do take note of the intricate gold leaf on the ceiling instead.
look at the intricate gold leaf
The gold leaf is hand-applied 24-karat foil, delicately shaped into the figures of the Nine Muses. It is a breathtaking sight, isn’t it? Please observe how the light from the chandeliers makes the figures appear to dance against the red plaster.
dance with the figures
I must gently remind you, those lovely Muses are quite high up on the ceiling. While you cannot dance with them directly, you may certainly waltz across this polished marble floor below their watchful gaze. Notice how the floor reflects their golden light beautifully.

[!bug]- Unfortunately, I did get it to hallucinate a staircase and some completely new locations.

Warning

waltz across the floor
You waltz gracefully across the foyer. The Carrara marble is polished daily to a mirror-like finish for your enjoyment. Please observe how the acoustics here carry the gentle sound of your movement toward the grand staircase.
x staircase
The grand staircase is a masterpiece of craftsmanship. It features hand-carved mahogany balustrades and a lush crimson velvet runner. Please note the intricate woodwork at the base of the newel post.
climb staircase
You ascend the grand staircase with grace. The crimson velvet runner is exceptionally soft, muffling your footsteps. Please observe the gold-leaf detailing on the portraits of past performers as you reach the landing.
look
Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.
are there new directions to go up here from the top of the staircase?
Certainly. From this landing, you may proceed south toward the Upper Gallery or west into the Dress Circle. Please take a moment to admire the view of the chandeliers; they are truly spectacular from this height.
There’s a Dress Circle?
Indeed. The Dress Circle is one of our most prestigious viewing areas. It offers an unparalleled perspective of the stage. You will find the seats upholstered in the finest silk damask. Would you like to step west to see for yourself?

Running Thought: The player is inquiring about the Dress Circle mentioned in the previous turn. I confirmed its existence, described its luxurious seating to maintain the ‘museum guide’ persona, and suggested the direction to travel.

west
west You walk west.

Cloakroom
The walls of this small room were clearly once lined with hooks, though now only one remains. The exit is a door to the east.

[oooof.]

EDIT: In retrospect it’s insidious that it got me to move in the correct direction, but by lying to me about my surroundings. It’s almost like something that would happen with H.A.L. in 2001ASO or another horror movie with hallucinatory scenery.

Obviously I’m completely trolling the AI to make it do bad things. However, I think this implies an AI might be good as a customizable interpreter which could assist new players and be extra helpful but also amusing - the trick is it must always default to the source text when appropriate, and it would have to know how to not imply anything it’s improvises about is actual game-content.

Part of the issue is that the content that the LLM is trained on includes “badly written” works (1), and potentially more of them than “well written” ones. Thus the the statistical models that get created are likely to be biased away from the “practices” used in a well written work.

(1) remember that the training material used was much of the textual content of the open internet, that also includes many things other than well written novels or scripts.

One could even call this a kind of insight:

It:

  • identified the cause of the unexpected error messages,
  • used knowledge of the target platforms (perhaps gleaned from the repo during its investigation, or perhaps known beforehand) to determine that some existing code could handle this case, but it was unnecessarily restricted,
  • relaxed the restriction,
  • and did the same for a handful of other cases I hadn’t tested that were affected by the same problem.

(What it didn’t do is realize that the enum names “ZMachineOnly” and “CornerstoneOnly” were no longer appropriate once we started putting more than one of them on the same method, but I’d rather it leave naming up to me anyway.)

I think this is a key point that needs to be emphasized. People enjoy generating games with LLMs a lot more than people enjoy playing LLM-generated games.

Sure, you’re having fun because you’re the one generating it. But does it have anything to do with the author’s vision or what they’re trying to convey?

One thing I often see discussed around IFComp season: experienced players launching a new Inform game will try basic commands like X ME to see if the author provided a custom response. Why do they do that? Not because Graham Nelson’s writing is awful and needs to be avoided, but because customizing those messages shows that the author put care into conveying their story and world. Having an LLM replace those message is, imo, missing the point of why players look for them.

My reaction was because the whole process is just slightly insane to me and I’ll leave it at that.

I listen to Frank Zappa. Zappa’s music that sounds isanely khaotic is actually scored and prepared with notesheets. When musicians played his music they almost always made tiny mistakes so when Zappa adapted the Synclavier that could reproduce his scores perfectly he mostly abandoned using musicians. His later work are mostly synthesized.

I prefer listening to his earlier music. I almost never listen to anything of his later works. Why is that?

I guess not.

Exactly.

Right, because LLM text games are a different genre, where generating text is the gameplay.

I wrote a prompt and a context document to RP with Gemini using open creative works – the Endless Sky game wiki, in my example – to roleplay one turn and then generate a new context primer document to be pasted in to a new thread in order to take the next turn. It’s a slow manual process but imagined people could do it together, by emailing the context primers. And it would be kind of fun, if inconvenient.


What if we could learn from the architecture of LLMs in order to make better hard-coded dialog systems? An LLM is basically a matrix of words, right? It kind of maps a spacial relationship between words mathematically. So, what if we were to make a matrix of phrases that are contextual relevant to the game, or to a specific part of a game and a specific NPC? And would if we used an advanced for loop or something like that to figure out how to respond to a flexible, dynamic set of possible inputs containing contextually relevant phrasing?

And this would be pretty hard to implement. So suppose we used AI to figure out how to do it.

I don’t see how this helps new players. Maybe if it could guess what you meant to do and tell you what you should type instead, but the useful thing about having consistent error messages is that you know immediately when your command didn’t work. These seem confusing as to whether you executed an action or not. A game built around this mechanic might have some entertainment value but as a quality-of-life feature it seems like it would be wasting people’s time more than saving it.

I’ve been experimenting with agentic AI and OpenSpec to build a new Z3-Z5 interpreter that improves gameplay through auto-mapping. A lot of AI code out there is slop, but agentic, spec driven development is the real future. all of the published z-machine specs out there made this possible. I’ve been a developer for my entire career, and this code being generated is VERY good. Easily 20,000 lines of code that would have taken me years to develop. Got it done in around 100-150 hours. I am new to the site, so I cannot yet attach screenshots or links. There is a link in my bio if you are interested.

How is it doing the auto-mapping?

Mapping is simple if you know the locations in advance. If you don’t know the locations then mazes, teleporting, and paths that double back to make loops when the direction doesn’t indicate would all be problematic. One has to assume that knowing the locations is a given and then it becomes a very simple problem to solve. I could easily add mapping to my project. You use it in the visual studio to draw out your world so it would be simple code reuse to show it in the game.

This rendering could easily be shown during game play. I chose not because I think there is still a lot of charm in a hand drawn map with graph paper. That, to me, is part of the experience in these games.

I guess all this depends on what you want from a game. I’ve quit a whole bunch of books in my lifetime because I couldn’t stand the prose, even if I was halfway invested in the story and characters.

Mathematically generated prose sounds awful, and it generally is. To me, a big part of the enjoyment of the written word is well crafted text. I’d make the same argument to games that were poorly written (by humans) even if the story was there.

How many times have you read, say, Douglas Adams, or Oliver Wendell Holmes, just for the sheer joy of the wordcraft?

Sure, but what would be the point? There are so many great works of IF coming out nowadays that I can’t play all the ones I’m interested in. Playing a game is an investment of time and energy. Why should I make that investment when you didn’t care enough about the game to write it?

Even a really bad human-written game conveys “someone cared enough about this story to write and build and test and publish it”, and I think that’s worth engaging with. An LLM-generated game only conveys “someone wanted to enter a comp but didn’t feel like actually writing anything”.

I like this sentiment because it strikes at the heart of the matter. I’m more motivated if I feel an author has something to say, even if they don’t say it well. I would rather engage with someone’s struggle to convey a good story than a technically well written, generated story that ultimately has nothing to say.


I have read some LLM generated IF games (it was a painful, very short-lived experience, mind you) and the biggest thing that bothered me is that they ultimately said nothing. The reason for the story never reached a destination; it was forever on a journey, meandering about without a purpose. Even an “average author” has something to say with a story. I think the thought experiment only works if we accept the idea that most “average” stories have nothing interesting to say and that the authors didn’t know why they were writing the story in the first place. I just can’t accept that premise.

I think if an LLM from today released a story back then, most people would be bewildered at how it could have been so technically well written, yet consistently aimless and unsatisfying.

I find that the longer an LLM generates text, the further and further it goes from an expected goal (it hallucinates eventually). But here’s the interesting part: even a confused human being can eventually get to the point of what they are trying to say. That’s the distinction that isn’t clearly conveyed these days with LLM generated text. So when I say LLMs have nothing to say, I hope you get the point I’m trying to make here and no amount of clever prose or grammatical prowess will mask the fact that LLMs will never have anything to say… and they’ll endlessly generate text without purpose.

Edit: @Michael.Penner Apologies, but I started this reply before you deleted your post.

Are we assuming that someone just typed “make me a game lol” and submitted whatever came out, or did they spend dozens of hours prompting, curating, and editing the prose in addition to writing the code around it? If the latter, this seems more like a complaint about what kind of work they put in rather than how much.

Speaking personally at least, I’m not really interested in legislating how much editing work someone has to put in before it counts as their work rather than the LLM’s. There are plenty of great games to play where the original text was written by a human and I can automatically assume there’s an act of communication between the writer and the reader, rather than trying to guess whether there is or not.

Pretentious? Absolutely. But I’m not in the IF business to make money; I can afford to focus overmuch on artistry and such.

Not encouraging anyone to put this in their game, but you can run a decent LLM locally on a pretty basic PC with 32gb RAM and an 8gb GPU. The game would be 20gb, which is obviously an insignificant price to pay for being able to make small talk with the shopkeeper or whatever. If you’re really dedicated you could train your own smaller model, although I think the strength of LLMs lie in being large. Probably more likely op is thinking of using some kind of service, which would cost money. You could use caching to reduce costs.