Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

List/Index of used variables

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

  • You need to state which Story Format you are using when you ask a question, as answers can be different for each one. As your question contains a reference to an (array:) macro I will assume you are using Harlowe,

    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.
    current: (print: Object.keys(State.variables))
    

    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.
  • edited June 2016
    The best way to do this is to create an xcel document with everything organised there in a map of what goes where.

    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.
  • edited June 2016
    I also just realised that Twine 1 does this functionality under its "Story Statistics" panel it displays a copy pastable list of all variables. Not really relevant if you're using Harlowe, but if it's functionality you really need, it's possible with a story format switch.
  • Claretta wrote: »
    it's possible with a story format switch.
    And a switch of which application they are using to create their story. *smile*

  • edited June 2016
    That was in context when I mentioned Twine 1. Technically I regard SugarCube in Twine 1 as a separate format to it in Twine 2 anyway, since it has features it doesn't have in Twine 2, such as the ability to load a javascript userlibrary.
Sign In or Register to comment.