Hello, I'm new to Twine and to scrypting at all, and my question is:
How can I make a list of variables already used in my story, in every paragraph? Is there such an option? Is there a possibility to automatically include used variables to that list/index?
I've tried to understand how are (database:) and (array:) working, but as far as I understand, they are not what I am looking for.
Thank you for answering!
Comments
I don't know of a built-in macro or documented method for seeing a list of names for the known variables.
You could try using the undocumented State.variables collection but that only contains the variables that are referenced in the Passage currently being shown to the Reader.
You could try using the undocumented State.serialise() method but the data structure that method returns only contains information about variables referenced in previously shown Passages, and you would need to process that data structure to extract the names you wanted.
You could try using a Scope Escalation hack to access the Passages module which contains the content of all the passages within your story, but then you would need to process the content of each passage looking for variable references so you can build your own list.
The way I track the names of all the variables with a story is to first add a startup tagged passage to the story, and then to make sure I assign a default value to each new variable within the startup tagged passage before I use that variable within the rest of the story.
But someone else may have a better answer.
This is the best option because if you're writing a complex story, you really need to be proactive about managing it, instead of trying to use automation. This is one of the standard features of a game design document: Everything is mapped out before coding.
I know this answer essentially amounts to "Go back and do something else", but I don't think there's any value in trying to circumvent the role of a game design document.
To avoid having to open each passage one by one, you can build your story into a html file, open the file in Notepad++, and do a "find" search for all set: occurances in the file or <<set if using Sugarcube, whatever equates to how you've set variables. Then each time you come across a set:, write down what it's doing and what passage it is in. That'll take a few hours depending on how big the story is, but once it's done, it's done, and you'll be more organised.