Howdy, Stranger!

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

Counting passed tags? (Harlowe online 2.0?)

Hi,
I am looking to count amount of times the person passed through a passage with a certain tag in it throughout the whole story and adds +1 if passed through.

If I pass through a tag A once, it should display: You've been in A 1 time
If I pass through it twice: You've been in A 2 times

I've tried to make it work with passage history tags contains:
(if: ( (passage: (history:)'s last)'s tags contains "A") )[You've been in A once]
(else:)[No A passages]

But have no idea how to make it work for multiple passages to add +1... Can anyone help me move forward with this?

Thanks!

Comments

  • I wouldn't call myself a Harlowe expert, so there may be an easier way to do this, however….

    In Harlowe v2.x, you should be able to do something like the following to get the count of passages within the history which contain the specified tag:
    (find: _p where _p's tags contains "A", ...(altered: _n via (passage: _n), ...(history:)))'s length
    


    Simply printing the count:
    You've been through passages tagged with "A" (print: (find: _p where _p's tags contains "A", ...(altered: _n via (passage: _n), ...(history:)))'s length) times.
    


    Because of the complexity of the construct, I'd suggest storing the result within a temporary variable if you'll need the value more than once within a passage. For example, using it with (if:) chain:
    {
    (set: _tagACount to (find: _p where _p's tags contains "A", ...(altered: _n via (passage: _n), ...(history:)))'s length)
    You've 
    (if: _tagACount is 0)[never been through passages tagged with "A"]
    (elseif: _tagACount is 1)[been through passages tagged with "A" once]
    (else:)[been through passages tagged with "A" _tagACount times]
    }
    


    NOTE: Do not attempt to run that on the starting passage as the history will be empty at that point, so the construct will fail.
  • How do implement this? When I've tried to run it I get:
    missing ) after argument list
  • Your subject line implied that you're using Harlowe v2. The code I gave was for Harlowe v2. Unless you made an error when copying the code, then you're likely using Harlowe v1 instead. To use the code I provided, you'll have to switch to v2—see: story menu > Change Story Format.

    I'm unsure if what you want is even possible in Harlowe v1—I know it's not possible natively, but it may be possible to access the history from JavaScript, which allows much the same thing to be done as the v2 code I provided.
Sign In or Register to comment.