A better way to refresh pages (Explaining Twine)
Added 2021-10-24 07:22:16 +0000 UTCIn Twine, you navigate around passages by clicking links. In code, the links look like this
<<link "Link name">><<goto "New Page">><</link>>
Of course you can make a link which will make you visit the same page you're on, again. So say you're on some main 'combat' page, aptly named "Combat", and you want to create a link that'll let you attack the enemy. It might look like this
<<link "Shoot bow">><<set $enemy.hp -= 5>><<goto "Combat">><</link>>
You'd go to the same page and as part of the click, you'd deal damage. Probably set something at the beginning of the page that'll swap whose turn it is every time you visit. Pretty simple and intuitive. In fact the main way I handle turns in combat is by revisiting the page. >_>;;
However, by visiting this page over and over, you're still visiting pages, which creates moments in the story's history. By default, Twine stories track history so as to let the player revisit/rewind passages, or see if a page was previously visited. A lot of data gets put into maintaining a copy of all variables and what their values were in the previous page, and the page before that, essentially maintaining exact copies of the game's state at the time... For up to 100 previously visited pages. But that's by default, so you can disable that.
You'll no longer create perfect copies of the game across all those previously visited pages, but the game still tracks what pages were visited, and how many pages you've visited so far. And you don't want to disable ALL tracking as it's useful to know if someone's visited a particular page before (say, so they don't get multiple copies of the same item).
This doesn't really matter if it's just a few hundred page visits but what about thousands? While I've yet to see any instance of performance taking a hit from total page visits alone (usually performance problems are caused by too many variables at once), it's prudent to not 'waste' total page visits. So one thing you can do is replace elements of the screen/page instead of reloading the whole screen whenever you take a turn in battle.
I've been trying this out and I found it to be significantly snappier, you can (in theory) take several turns in a second without any delay or problems, plus you can selectively update certain items instead of having to make ALL sprites and text refresh. I'll keep testing its limits and will definitely implement it in some later game, not 100% sure if I can put it into Slime Dungeon part 2 without a lot of annoying rejiggering though.