how to pass variables into Twine...

Hi there
I'm pretty new to Twine, and what i want to do is use it to create a bunch of different but interlinking stories that the user accesses as different characters. I want their entry into Twine to be determined by the link they click on which will then tell Twine to start that user at a particular passage, not necessarily the first one. Does anyone know whether this is possible, and if so, how?
thanks

Comments

  • You could do it with URL queries, e.g.
    http://mystory.com/twine.html?nav=Character%20A%20Start
    I have set up something like this in SugarCube that allows for any number of such URL queries that may do different things, e.g. set a variable, go directly to a different passage. You might have to modify the code if you are using a different header. Someone else here can help, I'm sure.

    First, put this in your StoryInit passage:
    <<set $urlopts to {}>>
    <<script>>
    state.active.variables.urlopts = parseQueryString( window.location.search.substring(1) );
    var opts = state.active.variables.urlopts;
    for (var key in opts) {
    if ( opts.hasOwnProperty(key) ) {
    state.active.variables.urlopts[key] = decodeURIComponent(opts[key]);
    if (state.active.variables.hasOwnProperty(key)) {
    state.active.variables[key] = state.active.variables.urlopts[key];
    }
    }
    }
    if (opts.hasOwnProperty("nav")) {
    SaveSystem.deleteAuto();//if you are using auto-saves in SugarCube, you probably want to delete any save before beginning
    config.startPassage = opts["nav"];
    }
    <</script>>
    And in a separate script passage:
    //from http://www.joezimjs.com/javascript/3-ways-to-parse-a-query-string-in-a-url/
    window.parseQueryString = function( queryString ) {
    var params = {}, queries, temp, i, l;

    // Split into key/value pairs
    queries = queryString.split("&amp;");

    // Convert the array of strings into an object
    for ( i = 0, l = queries.length; i < l; i++ ) {
    temp = queries[i].split('=');
    params[temp[0]] = temp[1];
    }

    return params;
    };
    Now you can provide the start passage as query in the URL that launches Twine, and that passage will automatically be set as the start passage.
  • Here's an easier solution for Sugarcane: simply publish the story, then add to the end of the HTML file's URL the text "#!name", where "name" is the name of the passage you wish to start from (for instance, for a HTML file called "story.html" with a passage titled "bicycle", make the URL read "story.html#!bicycle"). Note that you can only refer to passages with no punctuation or spaces in their names in this way.
Sign In or Register to comment.