Can Twine recall when a variable was changed?

Please specify version and format if asking for help, or apply optional tags above:
Twine Version:2.3.9
Story Format: Harlowe 3.1.0

Hi, so I’m a new user, still trying to wrap my head around how to get things done in Twine, but I’m also dumb enough to have dived right into the Twine game jam going right now on itch.io. It’s a stupidly ambitious game about the Trojan War, and I’ve finally gotten up to the end of the war, as the combatants are heading home (or not, if they died) and I was wondering if there’s a way to have the game check when the character’s variable was changed to ‘dead’, so I could have the ending say “You got him killed in the third year of the war” without my having to go back to every single passage (there are over 500 of them) and find every time a character might have died to add a new variable tracking how and when they died.

Looking around on this forum, I’m getting the impression that I probably should have used Sugarcube instead of Harlowe, but with about three days left in the game jam, I obviously don’t have time to go back and change it now. (I’ll be lucky if I even manage to get it spellchecked!)

So, is there a way to do this in Harlowe, or do I just have to add this to my list of “features I wanted to add but didn’t have time to for the game jam version”?

I can’t recall a Harlowe feature that will let you examine the story’s History to determine at which moment in the current playthrough a story variable’s value changed.

That being said it may be technically possible to make that determination, as long as you’re willing to use JavaScript to hack into the internals of the story format’s engine.

warning: The following explanation has been simplified, so while it is correct in a general sense it isn’t 100% technically correct.

Harlowe History system is based on a variation of JavaScript’s Object Prototype Inheritance, and based on the fact that variable’s are only referenced in the inheritance level they were changed in it should be possible to determine how many ‘Moments’ ago a variable was last changed.

1: Variable $name is initialised in the 1st Moment of history…

History: {
	name: "Jane"
}

2: Reader navigates to the 2nd Passage…

History: {
	prototype: {
		name: "Jane"
	}
}

3: Reader navigates to the 3rd Passage, in which the $age variable is initialised…

History: {
	prototype: {
		prototype: {
			name: "Jane"
		}
	},
	age: 18
}

4: Reader navigates to the 4th Passage, in which the $name variable is changed…

History: {
	prototype: {
		prototype: {
			prototype: {
				name: "Jane"
			}
		},
		age: 18
	},
	name: "Jane Doe"
}

So as you see in the example 4, you can traverse through the ‘History’ object’s prototype hierarchy to determine at which level a specific named property (variable name) was referenced, which equates to how many Passage Transitions ago that variable was changed.

Yikes. I think I’ll add it to my list of “next version” features, then. Even if I 100% understood this (I have no knowledge of Javascript), it wouldn’t work for me in this situation, because the number of passage transitions the player went through since the various characters’ potential deaths are too variable, since some routes involve more passages than others.

There’s a lot about the game that’s really sloppy on the back end anyway (like it took me until Year Eight to figure out that I didn’t need to copy-paste entire passages just to have a different character’s name in it) so when-they-died variables (or an array maybe) will just have to be something I add in when I clean it up after the jam is over.

Anyway, thanks for this; I might be able to use it in some later game. :slight_smile: