0 votes
by (150 points)
I'm creating a story using Twine 2.2.1 Sugarcube 2.21 that asks users to enter a lot of information using <<text area>> which is assigned to a variable . Everything works well as long as I keep moving forward, but any time I return to the previous screen -- using either the <<return>>  I've added or the back arrow on the interface -- I lose the value of the variable (the text) that has been entered before. Any ideas on what I am doing wrong?

2 Answers

0 votes
by (2.4k points)
selected by
 
Best answer
I'm not sure but I think <<back>> instead of <<return>> works in that case.
by (150 points)
Thanks Ralkai, but I already tried <<back>>, as well as linking directly back with [[return| "name of previouslink"]] and in each case when I go back whatever was written before in the text area has disappeared.
by (2.4k points)
Ok, it seems like the problem is how <<textarea>> needs a default value, so it is overwriting the content of the variable where you store the <<textarea>> content when you go back to that passage.

Using <<textarea "$myVariable" $myVariable>> seems to do the trick. This will use the content of the same variable where you store the textarea content as the default value, but you should define $myVar with a proper default value in the passage before to the one where you are going to use the <<textarea>> (otherwise you'll see an ugly "undefined" as the default value). However, I have the feeling that this is a clumsy fix and probably will fail under certain circunstances...
by (68.6k points)

> […] but you should define $myVar with a proper default value in the passage before to the one where you are going to use the <<textarea>> […]

In general, you should be initializing your variables within the StoryInit special passage.  Sprinkling them here and there throughout your passages can lead to issues.

 

by (150 points)
<<textarea "$myVariable" $myVariable>>  worked. Many thanks everyone.
+1 vote
by (159k points)

The Go Backward 'button' found in the navigation area of the left side-bar winds the story's History backwards one Moment in time, the <<back>> macro can be used to do the same thing. Both these actions undo any story variable changes done in the current Passage.

The <<return>> macro moves the story History foreward one Moment, thus any story variable changes should be persisted duing the associated Passage Transition.

If your story variables are reverting back you a previous state after using a <<return>> macro then it is likely that the Target Passage has <<set>> macros within it that is causing that behaviour. We would need to see an example of the related passages to determine what is causing your problem.

eg. an example of the Passage that is calling the <<return>> macro and an example of the Passage targeted by that <<return>> macro.

...