Howdy, Stranger!

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

External Link to the Story

It's Posible tu use a external link to a specific passage of the story? I'm trying to make a live story with QR codes and it would be great :)

Comments

  • Maybe it's that I'm a novice, but it seems like more information would be helpful. Are you trying to place a QR code in your story to lead out of it, so that the player scans it and it takes them to info on the web. Or to make one to come from outside into a passage? Seems like a little more info would be helpful. What do YOU mean by 'live story'? I'm guessing you want a 'Doom 3' or 'Missing' type thing where things in the game happen and players can go out on the net a find stuff out?

    Like I said though, I'm a novice and maybe that's why I don't get what you're saying, but a little more info never hurt. :) Just trying to help.
  • edited August 2015
    The impression I got was Klain wants to make an ARG where people can find QR codes, which link directly to a passage within a story. So a QR code for the link

    http://story_url?p=startpassage

    would start with the passage called startpassage rather than the default start point.
    There doesn't seem to be a way in twine to read the GET parameters, so in order for this to work you need to use some javascript to set a variable, and then in twine display the passage that this variable points to.

    Add the following to the story's javascript
    Wikifier.setValue("$startPassage", "");
    var queryDict = {};
    location.search.substr(1).split("&").forEach(function(item) {queryDict[item.split("=")[0]] = item.split("=")[1]});
    if(queryDict["p"]){Wikifier.setValue("$startPassage", queryDict["p"]);}
    

    And then put this in the story's start passage
    <<set $validStarts to [List of valid start passages]>>
    <<if $validStarts.contains($startPassage)>><<display $startPassage>><<else>><<display "default">><</if>>
    

    Note, I'm not very familiar with sugarcube. The above works, but there might be a simpler way.
  • edited August 2015
    A better SugarCube implementation would probably look something like the following. It avoids some of the query string parsing pitfalls in prof_yaffle's, doesn't create needless story $variables, ensures that the target passage exists, and makes use of the config object's starting passage property so you simply start at the appropriate passage (config.startPassage in SugarCube 1.x and config.startingPassage in SugarCube 2.x).

    It uses the same query string format as prof_yaffle's (i.e. "…?p=startingPassageName").

    For example: (goes in Story JavaScript)
    var query = (function () {
    	if (window.location.search === "") return {};
    
    	var query = {};
    	window.location.search.slice(1).split("&").forEach(function (kvPair) {
    		var i = kvPair.indexOf("=");
    		if (i === -1) {
    			query[kvPair] = "";
    		} else {
    			var	key = decodeURIComponent(kvPair.slice(0, i).replace(/\+/g, " ")),
    				val = decodeURIComponent(kvPair.slice(i + 1).replace(/\+/g, " "));
    			query[key] = val;
    		}
    	});
    	return query;
    }());
    
    // Use in SugarCube 1.x
    if (query.hasOwnProperty("p") && tale.has(query["p"])) config.startPassage = query["p"];
    
    // Use in SugarCube 2.x
    if (query.hasOwnProperty("p") && tale.has(query["p"])) config.startingPassage = query["p"];
    
  • edited August 2015
    Thrown wrote: »
    Maybe it's that I'm a novice, but ...
    The idea is to print codes to paste it in the real world XD. For example, if I write a detective story, it might choose a location such as a home and paste the codes to the rooms to represent the various places to visit like the player and paste the codes hidden in environmental objects like clues. The codes are used to be like links between passages.
    The impression I got was Klain...
    Yes, you are right, and thanks for de solution. Im going to try to undestand how to use javascript on twine first :P
    A better SugarCube implementation would probably look something like the following...
    Thanks for the sugarcube explanation too!

    Thanks to all responses! you have make my day!

    The only problem is that your responses are for change the starting passage. I'm trying to use the url to move into passages.
  • Klain wrote: »
    The only problem is that your responses are for change the starting passage. I'm trying to use the url to move into passages.
    By this do you mean you want the player to be able to move from one part of the game to another via using one of these codes?

    eg. The player is currently reading the Kitchen passage, the player scans a code and instantly moved to the Basement passage.
  • greyelf wrote: »
    By this do you mean you want

    Exact!
  • Okey, with the help of TheMadExile and prof_yaffle i have made this
    macros.add("QR", {
    		handler : function () {
    				if (window.location.search === "") return {};
    					var query = {};
    					var url=window.location.search;
    					state.active.variables["URL"]=url;
    					url.slice(1).split("&").forEach(function (element, index, array) { 
    						var i = element.indexOf("=");
    						var	key = element.slice(0, i),
    								val = element.slice(i + 1);
    						query[key] = val;
    					});
    					state.active.variables["P"]=query["p"];
    					if (query.hasOwnProperty("p") && tale.has(query["p"]))setTimeout(function () { state.display(query["p"])}, 40);
    		}
    });
    

    I guess the decodeURIComponent maybe must be necesary...but it works for me.

    Using the http://story_url?p=passage and the <<QR>> new macro on every passage i want, the macro move to de passage of the URL.

    In a example with 3 passages ( "Scene", "Clue" and "Resolution" ) I'll print 3 QR codes ("story_url?p=Scene","story_url?p=Clue","story_url?p=Resolution") and paste in a room, in a delineated body in the floor and in a toy gun.

    Then all passagse have his own little part of story and variables, and maybe links to other passages but the only way to access to clue or resolution passage is throug the QR code.

    Then if i put the <<QR>> macro on all posible passages, when someone finds the QRs on the room can access to specify parts of the story...

    I hope someone undestand what i want to made :P
  • Hey,

    I know this thread is already a year old, but I want to the exact same thing, but can't make it work based upon the discriptions here.
    But to not state a confusing question, here is it what I want to do. I am using Harlowe 1.2.2 in Twine 2.0.11, but I am not married to Harlowe, I just started with Twine a few days ago and still getting used to it.

    My plan is to create custom links for every node in my twine story, so people can start at every point inside the story. I don't need a start screen or even a starting point, because the story will be accessed via OR-Codes (for which I need the links).

    For me it sounds like Klain achieved exactly that with the above code, but I don't really know where to place it or in which environment it was used. I tried Harlowe and Sugarcube, but got Error messages both times.

    Can someone help me with this?
  • Since this thread was tagged with sugarcube—check the opening post—you should probably assume that at least some of the examples will be for SugarCube. Sometimes threads do receive answers for multiple story formats though, so tags aren't 100% reliable. Still, they're a good place to start.


    Anyway. As I type this, all of the given examples are for various versions of SugarCube, so they're not going to work in Harlowe as-is, though they might be able to be adapted.

    As to where to place it—I'm assuming you meant Klain's SugarCube v1 <<QR>> macro—it goes into your project's Story JavaScript—check the menu named after your project on the story map.
  • Thank you for your answer, I didn't have the time to switch to SugarCube, so I simply exported an html version for every passage and for every export setting the start point of the story to this passage. I know this is a hassle, but I only had about 40 passages and also used Twine to display certain information in an exibition and link them together.
    But I think it's time to leave Harlowe behind.
Sign In or Register to comment.