Howdy, Stranger!

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

Using if and history in Harlowe / Twine 2 - Having difficulties getting passages to link

Hello,

I want to create an itemized list, but only have the last two items on the list appear if previous passages have been read. Each item in the list should link to a different passage, and then link back to the list.

So far I have:
item1
item2
item3
item 4

(if: (history:) contains (a: "item1", "item2", "item3", "item4")(link: "do item 5")[(goto: "item5")]
(else:)[...]



(if: (history:) contains "item5")(link: "do item 6")[(goto: "item6")]
(else:) [...]

This is not working, though. Instead the passage before the itemized list is going straight to item5, which won't link back to itemized list.

I've also tried:

item1
item2
item3
item 4

(if: (history:) contains (a: "item1", "item2", "item3", "item4")[(link: "do item 5")[(goto: "item5")]]
(else:)[...]



(if: (history:) contains "item5")[(link: "do item 6")[(goto: "item6")]]
(else:) [...]

and
item1
item2
item3
item 4

(if: (history:) contains (a: "item1", "item2", "item3", "item4")(link: "do item 5")][(goto: "item5")
(else:)[...]



(if: (history:) contains "item5")(link: "do item 6")][(goto: "item6")
(else:) [...]



to no avail.

What am I doing wrong?

Comments

  • The second version is close, but there's a missing parenthesis after the if tests.
    (if: (history:) contains (a: "item1", "item2", "item3", "item4"))[(link: "do item 5")[(goto: "item5")]]
    (else:)[...]
    
    (if: (history:) contains "item5"))[(link: "do item 6")[(goto: "item6")]]
    (else:) [...]
    

    There's still a couple of other problems. You've got extra spaces in your links. Which means that when you click on "do item 1" it'll go to a passage ' item1 ' rather than 'item1'
    (if: (history:) contains (a: "item1", "item2", "item3", "item4"))
    
    Checks to see if the history contains an element that is an array containing "item1"..."item4", so it'll never be true. The quickest way to check if the history contains all four items is to subtract the history from the array containing those items and then see if the resulting array is empty.
    (set: $test to (((a: "item1", "item2", "item3", "item4") - (history:)).length))
    (if: $test is 0)[(link: "do item 5")[(goto: "item5")]](else:)[...]
    
  • [[do item 1|item1]]
    [[do item 2|item2]] 
    [[do item 3|item3]]
    [[do item 4|item4]]
    
    (set: $test to (((a: "item1", "item2", "item3", "item4") - (history:)).length))
    (if: $test is 0)[(link: "do item 5")[(goto: "item5")]]
    (else:)[...]
    
    
    (if: (history:) contains "item5")[(link: "do item 6")[(goto: "item6") ]
    (else:) [...]
    

    I've got this now, but when I play through it, after I complete items 1 - 4, and then the item 5 link activates, when i click it I get this error: I can't (go-to:) the passage 'item5' because it doesn't exist.►

    I've created this passage and have text in it, but in the editor it won't link the two for some reason.

    Thanks so much for the help.
  • What you've got should be working. The only thing I can think of is to check passage item5 to make sure that there aren't any extra spaces in the title.

    BTW I forgot to mention before that on the line checking if the history contains "item5" there's a space between the else part and the hook, which will stop it from working.
Sign In or Register to comment.