+1 vote
by (160 points)
I'm working on a series of stories that are meant to follow one after the other.

Is there a way for the first story to export out a text string that can then be parsed by the second story and read into the new story's set of variables? This way I don't need to run the character creation more than once.

3 Answers

+1 vote
by (2.7k points)
Not really. You could give each character a code, and enter that into part two to have you ready-made character. For example, the first letter of the code is BL if you chose blond hair, BR if you chose brown hair and BA if you chose black hair. The next letter could store the height of the player. This could be entered into a textbox in the second part.
by (160 points)
This is what I'm looking for. I know I can use + to concatenate everything together, but how do I break it apart again in the other story so that it can be separated out into the new story's variables?
–1 vote
by (62.7k points)
by (160 points)
Yes, I saw that thread. I want a much simpler solution. Thanks for replying, though!
0 votes
by (62.7k points)
edited by

If you don't want to use the other example and would rather stick to using codes of text, JSON is your best bet.

Live example. Edit: removed. 

Code:

:: StoryInit
<<set $player to {
    name : '',
    age : 0,
    description : ''
}>>

:: Start
[[New Character]]
[[Import]]

:: New Character
Name:
<<textbox '$player.name' $player.name>>

Age:
* <label>20s <<radiobutton '$player.age' 25>></label>
* <label>30s <<radiobutton '$player.age' 35>></label>
* <label>40s <<radiobutton '$player.age' 45>></label>

Description:
<<textarea '$player.description' $player.description>>

[[Created]]

:: Created
Name: $player.name
Age: $player.age

Description:
$player.description

[[Export]]

::Export
<<print JSON.stringify($player)>>

Copy and paste this code to import your character!

:: Import
Character code:
<<textarea '_import' ''>>

<<button [[Import|Created]]>>
    <<set $player to JSON.parse(_import)>>
<</button>>

This is an incredibly minimal example.  You may want to add niceties like a select all and copy all button, and you may want to encode the string as well.

I would not recommend developing and implementing your own code system, mostly because that seems like a lot more work, but if you do go that route, as suggested by @SmuJamesB, the simple answer is that there is no easy way to unpack that data back into story variables without a whole lot of <<if>>s and <<switch>>es, as far as I can tell.

All the other ways to achieve this will require some complex code. 

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...