0 votes
by (150 points)
I'm starting to have a pretty good idea of what I want to do with my game.

But parts of it requires that I keep track of several factions, with a lot of algorithms for resource gathering and combat simulations.

I played a turn-based Twine game that was really slow, several seconds, each time you clicked next-turn.

I'm worried I will run into a similar issue eventually. Or is that more up to making my code well optimized than a Twine limitation?

2 Answers

0 votes
by (63.1k points)
edited by

Thousands of stateful variables is usually a bad idea, even if you're following good practices, since the history system is going to be tracking and cloning those variables across every moment in the story. It becomes less of an issue if you don't use or limit the history system, and placing some variables outside the State object also helps. 

0 votes
by (159k points)

There are a number of reasons why a Twine based game may slow down the longer it is played but generally it is the result of lack of memory.

Two situations that cause the reduction of memory over time are:

1. Loading of media files (like images, audio, video),

These get stored either in the web-browser's or the application cache and the memory they use may not be released until after the game has ended. If you are planing of having a lot of media files, or very large ones, or both then you way want to think of ways of releasing the memory resource consume once it isn't needed.

2. The History system (and the Story variable state stored within it)

By default each time the story transitions from one passage to another (can be same passage) a copy of the current state (values) of all known story variables is made and that copy alone with the name of the Passage is added to the History system as a Moment. The default maximum number of Moments the History system can store depends on the story format you are using (Harlowe: unlimited(ish), SugarCube: 100), and the effect the storage of all those moments can have depends greatly on how many there are and how much data is being stored in those story variables. SugarCube allows you to configure the maximum number of moments that the History system stores.

Both of the above situations can especially effect turn based RPG like games because you generally visit a lot of passages repeatedly thus increasing the number of moments being stored.

by (150 points)
Wow, yes. That will end poorly quite quickly.

I will try to disable the History or limit it severely. Since my game is more a sand-box, it is not crucial to the story to be able to easily back up and try a different path as in other CYOA stories.

Thank you!
...