0 votes
by (160 points)
Hello guys,

I'm using twee2 with sugarcube2. I want to create a file for character definitions. I created a file named chars.tw2 and included to the main file with ::StoryIncludes. Problem is I can link to the passages in chars.tw2 but can not use the variables in this file. What am I doing wrong?

Thanks.

2 Answers

0 votes
by (44.7k points)
What do you mean by you "can not use the variables in this file"?  How are they stored?  How are you trying to use them?  Are you getting any error messages?

There's not enough information in your question to answer it.
0 votes
by (159k points)

notes:
1. The following explaination assumes that your chars.tw2 file contains at least one Passage that contains the <<set>> macros being used to initialise your character definitions. Because I don't know the actual name of that Passage I will use Setup Characters instead in my code examples, but any other name will work just as well.

2. The StoryIncludes special passage only forces the twee2 compiler to include the child passages contained within the child files listed into the story HTML file being generated, it doesn't cause the execution of any of those child passages.

3. There should only be one StoryInit special passage per project.

The ideal place to initialise your story variables is within your project's StoryInit special passage, and you can use the <<include>> macro within that StoryInit to include any child passages that also contain story variable initialisations. (like the child passage mentioned in point 1 above)

So the contents of your project's StoryInit special passage would end up looking something like the following, obviously I don't know the names of your project's variables so I have added some meaningless ones of my own.

/* Initialise the project's story variables. */
<<set $counter to 1>>
<<set $list to ["one", "two", "three"]>>

/* Initialise the character story variables found in chars.tw2. */
<<include "Setup Characters">>

 

...