Howdy, Stranger!

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

Twine Techniques - Entry macros

Splitting this out of the Agency thread, a technique for using twine more effectively.

I commonly use an entry macro - a routine that gets called at the entry to almost every room.  The most important (and often the only thing it does) it to print out the $entry variable.
::entry
<<$entry>>

::room1
<<entry>>
Why?  Well, on the link from any other room, you can use the tail of the link to set the $entry variable, which becomes the first paragraph displayed on the next page:

[quote]::Choice
How do you wish to play this game:

[[As a man|Begin][$entry to "Your name is Mark Tellerman.  You are 28 years old and you were born in Queens.  You joined the army and eventually became a special ops soldier.  You left the army a couple of years ago after a disagreement with your commander and you are now working as an homicide detective with NYPD.<br><br>You don't remember a lot about last night - you ran your karate classes at the local community center as usual, had a drink with a couple of the other instructors and...somehow you got him. With a big rip in your jeans.  Weird.<br><br>Then, to cap it all, you get a call from dispatch at 5am telling you to investigate a murder...";$player_name to "Mark"]]
[[As a woman|Begin][$entry to "Your name is Jane Lu, you are 28 years old and are Chinese American.  You were born in Queens, and you've always had an interest in things Chinese, so much so that you went and lived there for a few years.  You hold a black belt in Karate and know quite a lot about Chinese history.  You worked as a US customs agent for a while before you decided to settle down and joined NYPD, where you ended up as a homicide detective.<br><br>You're not sure how you got home last night.  You ran the Karate class you normally teach down at the community center, chatted with the other trainers for a while and then...you work up in your bed this morning.  You've no idea how your best jeans got ripped either.<br><br>You're also feeling a bit off balance this morning because your usual morning ritual of tea and Tai-Chi has been disrupted. Dispatch called you in at 5am to investigate a murder.";$player_name to "Jane"]]

::Begin
<<entry>>

You've gotten to the address dispatch gave you - a run down warehouse - but somethings wrong.  There should be police cars and a coroners van here, but yours is the only car to be seen.

[[Get out and have a look around?|Whouse1][$entry to "You climb out of your car, check your gun and cautiously proceed towards the warehouse."]]
[[Call dispatch and check the address|Dispatch1][$entry to "You pick up the radio and call in."]]

This gives you a lot of flexability to blend between passages, while minmizing the actual number of passages you need, as, for some choices, the flow never actually diverges.

Comments

  • This is a good idea.

    You also you could add another variable in there too for important decisions you want to remind the player in a summary later. You could add a string to an array variable called say $PlotSum, so with every important decision the player makes you can store it.  So when you want to give the player a recap of events and key choices they made it will be set and outputted in the right sequence. 

  • Have you considered using prerender to do that? You would have have to type <<entry>> on each page.

    http://strugglingwithtwine.blogspot.co.uk/2014/03/prerender-and-postrender-in-twine.html
  • Hmmm. If I was comfortable writing and sharing Javasript and it needed it on absolutely every page, then, yeah, a prerenderer might be the way to do it.
  • For those using the SugarCube story format it includes two special passages PassageReady and PassageDone that can be used to achieve a similar effect.
  • The wrote:

    Have you considered using prerender to do that? You would have have to type <<entry>> on each page.

    http://strugglingwithtwine.blogspot.co.uk/2014/03/prerender-and-postrender-in-twine.html


    I checked out that link and had a mess around with the short scripts on there which work fine for placing a title or footer on every passage.  However I want to be able to have a block of text show in a passage that has a specific tag.

    So I have been messing around with a little script. This code below doesn't work, it's a self modified version of a script i found in that blog link. I do not know enough about what I am doing to get it to work.

    Any ideas how to get this working? a long the lines of...
    postrender.TagFooter = function(content) {

    var foot = tale.lookup("tags", "office001");
    if (foot.id !== undefined) {
    new Wikifier(content, "Postrender tags only- test successful"\n);
    }

    }
    Also how would you include text strings to also display with something like eg.
    new Wikifier(content, "The office room is <<$VarRoomSize>> with only <<$var1>> desks and <<$var2>> adjoining rooms. The decor is <<$VarDecor>>"\n);
    Of course this wouldn't work as I have written it because the script is in a different language right?
    Is this possible to do so somehow?

    The blog link sited- does have a tags footer script but that doesn't work (well in sugarcane at least- haven't tried it in other story formats).

    I basically want to be able to use this for dynamic descriptions of interior buildings and be able to just place the room or building type into the tags of location passages. The pre-defined variables added would help with giving a little randomness to the description. Or it might be better to have the random part integrated into the script itself so it randomly chooses an array index and then fetches a word or sentence from a string variable.  This system would enable more dynamic room descriptions. This might be better being a prerender?

    However the problem would be if the player entered a location and exited and returned the layout or description would be different.  So the solution (guessing here) perhaps on the first visit a unique variable is added to the passage that has the complete dynamic output from the script placed in it.

    Initially maybe each location passage has a unique variable $VarPassagename. The script runs when the player enters a passage that matches the tag then fetches the variable belonging to it and inserts the dynamic text output into that variable (as per my example code above).    When the player revisits the same tagged location and if $Varpassagename neq "" then the script will exit early and not run.

    Is this at all doable? or is there a better way to achieve this if it is possible? or perhaps you will question what the heck I am drinking? lol

  • mykael wrote:

    Hmmm. If I was comfortable writing and sharing Javasript and it needed it on absolutely every page, then, yeah, a prerenderer might be the way to do it.


    Try this:
    prerender.entering = function(content) {<br />&nbsp; if (state.history[0].variables.entry == undefined) return;<br />&nbsp; new Wikifier(content, state.history[0].variables.entry);<br />&nbsp; state.history[0].variables.entry = undefined;<br />}

    Put it in a script passage, then you no longer need <<entry>> and the entry passsage. It will only add the text if it was set on the previous page.
  • Such a simple idea, but a really brilliant technique, great for cutting down on passages.  Thanks for sharing, mykael, and the prerender macro looks interesting too Pixie :).
  • Dazakiwi38 wrote:
    So I have been messing around with a little script. This code below doesn't work, it's a self modified version of a script i found in that blog link. I do not know enough about what I am doing to get it to work.

    Any ideas how to get this working? a long the lines of...

    Try this:
    postrender.TagFooter = function(content) {
    if (this.tags.indexOf("office001") != -1) {
    new Wikifier(content, "Postrender tags only- test successful"\n);
    }
    }
    [quote]Also how would you include text strings to also display with something like eg.
    new Wikifier(content, "The office room is <<$VarRoomSize>> with only <<$var1>> desks and <<$var2>> adjoining rooms. The decor is <<$VarDecor>>"\n);
    Of course this wouldn't work as I have written it because the script is in a different language right?
    I would guess that that would work. It is all the same language (JavaScript), and the Wikifier will sort out the macros for you.
  • Thanks Pixie for your reply.  I tried the script;
    postrender.TagFooter = function(content) {
    if (this.tags.indexOf("office001") != -1) {
    new Wikifier(content, "Postrender tags only- test successful"\n);
    }
    }

    And in google chrome it gave me this error; "There is a technical problem with this story (Untitled Script 1: Unexpected token ILLEGAL).." etc.

    Also is it possible to also have the script display a specific passage? and also set some variables? It would be handy once this script works, to be make use of it in many ways with tags. This way when the player enters certain locations with specific tags you could have stats updated and values changed from within the script and keeps the passages less cluttered.


  • Dazakiwi38 wrote:

    And in google chrome it gave me this error; "There is a technical problem with this story (Untitled Script 1: Unexpected token ILLEGAL).." etc.


    I believe the \n in the Wikifier line needs to be before the end quote, as it represents a newline.

    postrender.TagFooter = function(content) {
    if (this.tags.indexOf("office001") != -1) {
    new Wikifier(content, "Postrender tags only- test successful\n");
    }
    }
  • greyelf wrote:

    Dazakiwi38 wrote:

    And in google chrome it gave me this error; "There is a technical problem with this story (Untitled Script 1: Unexpected token ILLEGAL).." etc.


    I believe the \n in the Wikifier line needs to be before the end quote, as it represents a newline.

    postrender.TagFooter = function(content) {
    if (this.tags.indexOf("office001") != -1) {
    new Wikifier(content, "Postrender tags only- test successful\n");
    }
    }


    Thanks for that Greyelf got it working now :) and thanks again Pixie for suggesting the alteration.

    I can confirm also as Pixie said the new wikifier handles the macros just fine, so long as its within the "" for that line of code with the new wikifier. Duplicate that line of code if you want more text and macros added. 
    This is great! opens up new possibilities.  ;D

    For those new to twine and learning as you go like me, if you want this script to output before the rest of the passage with the tags that triggers this script; change postrender. to prerender. at the top of the script and it will be so.
Sign In or Register to comment.