Howdy, Stranger!

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

[Harlowe] A question about variables

Apologies if I'm phrasing this in a slightly abstract way.
I have a grid of nine passages (three by three) that each connect to the passages left/right/up/down from them.
Each passage has two pieces of text in them. Is there a way to make my story so that once you've arrived at a passage it plays the first half of the text and if you arrive at the passage again it plays the second half. As it's a grid, with relatively free movement, it wouldn't work to have the passages around each particular one have a set to true command. I might be overthinking this, but any help would be gratefully accepted.

Comments

  • Hi, how about?
    (if: (history:) contains "name_of_your_passage")[Text to be displayed on first visit](else:)[Text to be displayed on subsequent visits]
    
  • Harlowe's documentation lists a macro named (history:) which contains a list of all the passages the Reader has visited before the current passage being shown.
    Harlowe's project overview lists a macro named (passage:) that contains information about the current passage being shown.

    The following examples combines these two macros to check if the Reader has visited the current passage before:
    (if: (history:) contains (passage:)'s name)[You have been here before](else:)[First Time Here!]
    
    note: The (history:) macro contains the list of all passages the reader has visited (prior to the one they are currently viewing), in the order they were visited and it may contain the same passage name more than once if the Reader has visited it more than once.
    So as the Reader travels through your story the number of items in the (history:) macro get greater and greater, which causes the time taken to determine if the list contains a particular Passage name a little longer each time the list size increases.

    Over use of the (history:) macro on story's with very long paths can cause the Reader ability to interact with the story to slowdown.
  • Amazing! Thank you, both. That's exactly it.
    And also a reminder to always go back to the documentation before asking a question...
  • While we're discussing it, is there a way to use (history:) that can change the text of a passage if you visit it twice, for example. As in a specific chunk of text displays if you visit the passage a certain number of times, but still using the (history:) function.
  • And also a reminder to always go back to the documentation before asking a question...
    I'm guessing you did not look at the documentation and see the (count:) macro?
    (set: $numberOfPreviousVisitsToCurrentPassage to (count: (history:), (passage:)'s name))
    
  • greyelf wrote: »
    And also a reminder to always go back to the documentation before asking a question...
    I'm guessing you did not look at the documentation and see the (count:) macro?
    (set: $numberOfPreviousVisitsToCurrentPassage to (count: (history:), (passage:)'s name))
    

    You have guessed right, sir! Have I learnt my lesson? Find out on the next exciting Twine Forum Question! (hopefully the answer is yes.)


    Also, thanks again.
  • You have guessed right, sir! Have I learnt my lesson? Find out on the next exciting Twine Forum Question! (hopefully the answer is yes.)


    Also, thanks again.

    I see what you did there XD
  • Okay, nope. Forgive me ineptitude, but I'm still not getting it.
    I've written:

    (set: $number to (count: (history:)))
    (if: $number is (either: 5,8,13,16)[*You’ve recovered these things,
    Do you remember yet?])

    The desired effect is that the text will display when the number of passages visited is any of those numbers. It's telling me however that I'm writing both commands wrong. What am I missing?
  • The first problem is the count macro needs 2 parameters, the array it's searching through and the value it's counting. In your case it'd be
    (set: $number to (count: (history:), (passage:)'s name))

    The either macro returns one of it's parameters at random. So it'll choose one of those values at random and check if $number is equal to that. It might be what you want, but I thought I should mention it in case you thought it'd check if $number was equal to any of those numbers.

    The last problem is the second close bracket is in the wrong place. It should be written as:

    (if: $number is (either: 5,8,13,16))[*You’ve recovered these things,
    Do you remember yet?]
  • Thank you, that's really useful.
    Especially highlighting my error of using (either:) in this situation. Is there a way of getting it to check whether $number is equal to any of the numbers in the string?

  • edited September 2015
    note: When you want to include a block of code in your comment please either use the C button (in the tool-bar above the comment field) to wrap your code bite in set of [ code] / [ /code] tags or add the tags manually. (there should be no space character between the [ and the next character, I needed to put it in to show you the tag to use.)

    Two methods to do what you want.
    A. Using the or keyword
    (if: $number is 5 or $number is 8 or $number is 13 or $number is 16)[*You’ve recovered these things,
    Do you remember yet?]
    

    B. Using an array and the contains keyword.
    note: this method should only be used if the are many values to check against, four is normally way below the minimum I would use it for because this method takes time to create the array and time to search the array, so it is generally better to use method A.
    (set: $list to (a: 5,8,13,16))
    (if: $list contains $number)[*You’ve recovered these things,
    Do you remember yet?]
    
Sign In or Register to comment.