Howdy, Stranger!

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

[Sugarcube 2.16.0] Pluck a tagged passage from an array

I have several passages with several tags like this:
:: Event1 [event suburbs]

My sidebar uses tags().includes("event") check to show some special info, and that works fine.
However when I try to get all the passages with "suburbs" tag, I don't get any. The code I'm using:
<<set $suburbs to Story.lookup("tags", "suburbs")>>

To get that particular passage into the array I need to change it to:
<<set $suburbs to Story.lookup("tags", "event,suburbs")>>

But the set of tags might be different per passage, so I need a way to get all the passages, one of which tags is "suburbs". Is there a way to do this?

After I get the list of these passages I need to create a link, which would pluck one passage and <<goto>> it. But I get an error with different variations of this code:
<<link "To the Suburbs">>
    <<set _e to $suburbs.pluck()>>
    <<goto _e>>
<</link>>

Could you help me, please?

P.S. using sugarcube 2.16 with entwine, if that matters.

Comments

  • Phalcon wrote: »
    I have several passages with several tags like this:
    :: Event1 [event suburbs]
    

    My sidebar uses tags().includes("event") check to show some special info, and that works fine. However when I try to get all the passages with "suburbs" tag, I don't get any. The code I'm using:
    <<set $suburbs to Story.lookup("tags", "suburbs")>>
    
    Then you've done something wrong someplace or entwine is mishandling tags, because that is the correct way to get an array of all Passage objects which contain the tag suburbs. The code in question is beyond well tested at this point.

    That said. As noted by its documentation, the Story.lookup() static method yields an array of Passage objects, not passage titles, which is what you seem to want. You should probably be doing something like the following:
    <<set $suburbs to Story.lookup("tags", "suburbs").map(function (p) { return p.title; })>>
    


    If that doesn't work, please post a copy of a project compiled with entwine, so I can look at what it's doing to tags.
  • Either I am doing something wrong, or that's not working.

    Also tried to import the file into Twine2 but it got stuck on "working" screen. Not sure that should have loaded though.

    I'm sorry for the mess in the project, I'm testing some stuff there :flushed:
  • If the Twee notation you're using actually looks as it does in your example from the opening post, then Entwine is doing something very, very wrong.

    Tags are being stored within the passage data separated by commas, rather than the correct spaces. For example:
    → This Twee passage header.
    :: Event1 [event suburbs]
    
    → Should generate a tags attribute like the following.
    tags="event suburbs"
    
    → Entwine is erroneously generating the following tags attribute instead.
    tags="event,suburbs"
    


    That seems to indicate that Entwine is broken. A brief check of its source code confirms that assessment—I think that all space separated values stored in arrays are broken, actually, not just tags.

    Anyway. I'd say that you'd probably want to report that, but the project doesn't seem to have an issue tracker. I suppose you could send CK a PM here or an e-mail instead. *shrug*
  • I've sent a PM to CK, hope he could help. I like creating a story based on the directories and different files with an external text editor.

    Thank you for you help!
  • edited April 2017
    If the Twee notation you're using actually looks as it does...

    I've recently found your TweeGo project, why wouldn't you advise me to try it? Looks like it's doing everything I need out of the box. Are there any special differencies or lacking functionality I should know about? Other than the need to include ::StoryTitle passage, usage of js/css by tagged passages instead of files and the default targets/sugarcube-2 directory for the format files :)

    Also is there an easy way to compile all the files in folder and subfolders not listing all the files by
    tweego src/* /src/events/* etc
    

  • Phalcon wrote: »
    I've recently found your TweeGo project, why wouldn't you advise me to try it?
    People do not, generally, decide to use a Twee workflow without knowing about their options. I, naturally, assumed you knew about the various Twee compilers and had chosen Entwine for a specific reason.

    Phalcon wrote: »
    Are there any special differencies or lacking functionality I should know about?
    The current TweeGo release only supports Twine 1 style story formats. The next release should support Twine 2 story formats as well.

    Phalcon wrote: »
    Also is there an easy way to compile all the files in folder and subfolders not listing all the files by
    tweego src/* /src/events/* etc
    
    Off the top of my head, not built in, no. Though, that's something I could add to the next release.

    Depending on your shell/binutils, there are likely ways to accomplish that goal independent of TweeGo.
Sign In or Register to comment.