Twine Coding Issue

Not sure this goes here in the programming section but seemed the logical choice to me. Basically, I’ve got a passage with a massive amount of text in it - conditional passage text based on a number of variables. When I test the passage there are a couple of errors that flag up about a missing closing tag for the first IF statement, and an orphaned ELSE tag. I’ve tried going through it line by line and can’t find the source of the error (though I did fix one other error that was cause by a mal-formed tag). Is there a tool in either the Twine editor that I can’t see or in browser that can pinpoint where the error is? I’m hoping there is so I don’t have to copy everything into Notepad or something and remove all the text to see just the code - or have to shuttle everything into umpteen individual passages with "GOTO"s in the main passage conditionals. Any help much appreciated.

What story format are you using? They’re all a bit different. SugarCube, Harlowe, Chapbook, Snowman?

I’m not familiar with any specific tools for the story formats for this specific sort of thing. It sounds like you’re missing the closing somewhere. I’d suggest copying it out and indenting each block or creating a regular expression to help you find blocks?

Though, I have just been using Tweego and Visual Studio Code though to make it just easier to manage the story as a set of files in git. Then its easier to test earlier and snap in changes as I make them, so if something does go awry it’s easier to undo and get back to a good state.

The Twee extension for VS Code does do some brace matching help for Harlowe, but not sure about how that translates to other story formats.

1 Like

The only way that I’m aware of to really get a better idea of which statement is causing the error is to right click and inspect the text (or press F12) and click as many of the dropdowns as you can in the developer tools interface.

It doesn’t sound like it would be too terrible to fix manually, though. An orphaned else tag just means that you placed one too many closing tags before the else, and you just need to move it to following the else statement.

A missing closing tag for the first if statement could be easy to fix, depending on the context. If it’s a statement that’s relevant for the whole passage, then you’d simply add another closing tag at the end and it would be fixed. Otherwise, you’d need to specifically pinpoint when you want that conditional to end and add a closing tag there.

What @drxprime said would probably be helpful as well. Temporarily indenting each block to know exactly how deep you are in conditionals would make it much easier to identify any premature or missing closing tags. Worst case scenario, I’m sure someone here (myself included, assuming you’re working with sugarcube) would be willing to potentially look at the passage in a DM to try to find the issue.

1 Like

If you’re having trouble matching opening/closing tags, maybe splitting the text chunks into another file is the thing to do, like it or not.

Using Sugarcube. Yeah I’m think the way to go might be the hard way of copying it off to notepad/splitting it up into multiple passages. The difficulty is the passage content making it hard to keep track of where the statements begin and end - though I’m pretty sure I wrote out all my case statements first and then put the content into them.

I did try the developer tools that were suggested but while it could identify where the errors were occurring in code lines/columns they were virtually meaningless to actually find in the Twine passage.

Thanks for the suggestions guys. I was dubious there would be a quick way but thought best to check anyway.

EDIT: Found the issue I think. The errors have gone away at least. Had an IF right at the start of the passage that when false has a short scene and negates everything else. Then everything else was encapsulated in an ELSE from there. Separated the two states out into separate IFs and that seems to have done the job. I don’t think it should cause an issue - given that variable can only be true or false and I’m explicitly stating what happens in each case rather than using ELSE.


Remember that you can conditionally call passages in Twine from other passages for printing (the “include” macro). It’s often better to have a passage of code that calls other passages of text, so you can mentally separate your two editing mindsets (code versus prose) and avoid having huge blocks of non-code obscuring your code errors.

Yeah I’ve done that for a couple of passages too - mainly things like the Character page references the Character Setup passage for the text that actually shows up there. I thought about doing something similar for this passage but couldn’t wrap my head around how to structure the call in the context given the nested statements. When I’ve done include and print before it was easy to make a variable like $playereyesdescribe that prints on the character page that gets set in the character setup passage based on the value of $playereyecolour but to structure narrative in this way is pretty counter intuitive to me.