Howdy, Stranger!

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

Displaying a text in all passages tagged with specific tag

Hello all,

is there a way to put some text in all passages with the same tag? So that, for example, if I have several passages tagged "shop", I could add something like
<<if $broke>>[[Visit a bank]]<<endif>>
at the bottom of each of those passages and not worry if I add any more "shop" passages and have an easy way of changing it if I decide to track money to "<<if $money eq 0>>", for example.

Comments

  • Hrmmmm... okay. This ain't official, but lemme give it a shot.

    Make a passage with just that bit of code in it. Give it the tags "shop" and "footer".

    Then put this into a script passage:

    postrender.tagFooter = function(A) {
    var i,j, feet = tale.lookup("tags", "footer");
    for (i = 0; i < feet.length; i++) {
    for (j=0;j<this.tags.length;j++) {
    if (!feet[i].tags.indexOf(this.tags[j])) {
    new Wikifier(A, feet[i].processText());
    }
    }
    }
    }
    Done and dun.
  • Awesome, it works like a charm.  ;D Thanks a lot.
  • How would I use something similar to add debug output to every passage?
    <<print JSON.stringify(state.history[0].variables)>> for example.

    I'd like to have the ability to display that at the bottom of every passage, although not multiple times
    if I include text from another passage using the <<display>> macro.
  • nomdepony wrote:

    How would I use something similar to add debug output to every passage?
    <<print JSON.stringify(state.history[0].variables)>> for example.

    I'd like to have the ability to display that at the bottom of every passage, although not multiple times
    if I include text from another passage using the <<display>> macro.


    Here's a variant that puts the code of a passage titled "StoryFooter" beneath every passage:

    postrender.StoryFooter = function(A) {
    var foot = tale.get("StoryFooter");
    if (foot.id !== undefined) {
    new Wikifier(A, foot.processText());
    }
    }
  • L wrote:

    nomdepony wrote:

    How would I use something similar to add debug output to every passage?
    <<print JSON.stringify(state.history[0].variables)>> for example.

    I'd like to have the ability to display that at the bottom of every passage, although not multiple times
    if I include text from another passage using the <<display>> macro.


    Here's a variant that puts the code of a passage titled "StoryFooter" beneath every passage:

    postrender.StoryFooter = function(A) {
    var foot = tale.get("StoryFooter");
    if (foot.id !== undefined) {
    new Wikifier(A, foot.processText());
    }
    }


    This is a great little script. I'm using this to display the stats on every passage, however at the very first instance the variables haven't yet been initialized in Start. The script runs before, but afterwards the display of variables in the stats is fine. 

    Is there a way to delay the script to run after Start passage runs?

    Is there a better method to display an inventory/Stats such as using the sidebar?  or being able to use a bordered text box around the stats below the passage as in using the footer script? so its less intrusive.  I did come across something like this a few days ago but cannot remember where I saw it. Unfortunately a google search for twine brings up other applications and topics as well.
  • Yes, there is. HarmlessTrouble wrote the module for me and L wrote a patch for it so that it wouldn't stop the new link variables from working.

    Judging from some of your other questions, you might not find this really easy to implement. But, maybe you'll get it no problem and I hope you do! :) If not, don't burn your brain trying. Just let me know and I'll write a demo for you. I'd do so now, but it will take some time so I'll wait until you try first.
  • Thanks Sharpe for your reply.

    I got it working and borrowed your code to that has the border around the passage, with sidebar removed.  It looks good. I will probably use that for my current project, if you don't mind me using it?

    However if I wanted to keep it more vanilla and didn't use the bordered look etc, and keeping the sidebar, how can I line up the passage link(s) with the other options already there like Restart and Book mark so its all in the same column as it were? I probably preferably use the screen space after 'This story was created by twine'..etc..

    Without creating another thread (or should I?)

    Is it possible to have a sidebar on the other side of the screen as well that you could used for displaying images?
  • I don't mind at all, but man, I wrote that all before I took the time a couple days ago to learn the fundamentals of CSS. That code is beyond ugly and also has some issues.

    You see the Plain Stylesheet I posted in the Workshop forum? It's basically the exact same thing but without all the mess and landmines waiting to go off with that really old ragged thing you downloaded. ;D It's all commented as if a new user is editing it as their first stylesheet.

    But, yes, I can now move that box around to pretty much anywhere no problem.

    My main game, Abaddon, is in serious need of a complete re-write of its stylesheet. I'll do so and get back with you. Just chill on it for now, I'd suggest.
  • Sharpe wrote:

    I don't mind at all, but man, I wrote that all before I took the time a couple days ago to learn the fundamentals of CSS. That code is beyond ugly and also has some issues.

    You see the Plain Stylesheet I posted in the Workshop forum? It's basically the exact same thing but without all the mess and landmines waiting to go off with that really old ragged thing you downloaded. ;D It's all commented as if a new user is editing it as their first stylesheet.

    But, yes, I can now move that box around to pretty much anywhere no problem.

    My main game, Abaddon, is in serious need of a complete re-write of its stylesheet. I'll do so and get back with you. Just chill on it for now, I'd suggest.


    Well you are ahead of me. But the main thing is it works.  The only issue remaining is the variables for the stats start off with 0 which is fine because the player hasn't chosen a role. Once they do the stats only display some and others have like [object object] until the next passage is entered, then it displays the stats properly.


  • Oh, Lord, I thought you just meant the CSS. You're founding a game off some old pre-release version of Abaddon? Yikes. I'd think that would cause you more headache than help.
  • Sharpe wrote:

    Oh, Lord, I thought you just meant the CSS. You're founding a game off some old pre-release version of Abaddon? Yikes. I'd think that would cause you more headache than help.


    Its from this link you gave me before https://groups.google.com/forum/#!topic/tweecode/_0qxlGzvfRA


    the colour doesn't change, the green from the StoryRegion stylesheet seems to over-ride it?
  • Man . . . I'm telling you, anything to do with any sort of code in that thing is borked. I know you say "it works," but it doesn't really.

    Good news is, I'm re-writing the CSS right now. I'd seriously just chill for tonight or at least for an hour or so.

    Attached is a pic as proof.

    EDIT: Also, if you're using the fledgling combat engine I wrote from scratch, I'd really rather you not for a number of reasons. For one, it sucks. However, I'm going to write a basic RPG that will be object-based and more easily modified with legible code. Basically, in all ways better. I took some time off to delve into JavaScript, but I'm back to it now. It won't be long.
Sign In or Register to comment.