Howdy, Stranger!

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

Variables / (If:) in Harlowe

Hi all,

I am delving into Twine for the first time and am really struggling to understand the correct usage of some of the macros. I have a passage where, after three links are clicked, I want a fourth link to appear. I tried doing this with variables, but it just isn't working:
{(set: $ticket to false)
(set: $ledger to false)
(set: $leaflet to false)
}

[Examine the paper ticket]<getticket|
(click-replace: ?getticket)[(set: $ticket to true)[Description of ticket.] ]

[Examine the ledger]<getledger|
(click-replace: ?getledger)[(set: $ledger to true)[Description of ledger.] ]

[Examine the leaflet]<getleaflet|
(click-replace: ?getleaflet)[(set: $leaflet to true)[Description of leaflet.] ]

(if: $ticket is true and $ledger is true and $leaflet is true)[Content appears]
The variables appear to be changing, but the hook after the (if:) never appears. I then tried to find my error by creating a simpler passage where just one variable triggers a link to appear, and that passage isn't working either.
{(set: $ticket to false)}

[Examine the paper ticket]<getticket|

(click-replace: ?getticket)[(set: $ticket to true)[Description of ticket.] ]

(if: $ticket is true)[Content appears]
I'm assuming something is wrong with the ability of (if:) to detect the variable change, but I'm not sure what. Any help is appreciated.

Comments

  • Your assumption is correct. By the time the player clicks on any of the options the (if:) macro has already been run and there's nothing to cause it to rerun.

    There's two options:
    1: move the initialisation macros into an earlier passage. The best option would be to put it in a new passage which is tagged 'startup' so the flags get set when the story is run. Then change the click-replace lines to redisplay the passage:
    [Examine the paper ticket]<getticket|
    (set: $here to (passage:)'s name)
    (click-replace: ?getticket)[(set: $ticket to true)[Description of ticket.] (goto: $here)]
    
    [Examine the ledger]<getledger|
    (click-replace: ?getledger)[(set: $ledger to true)[Description of ledger.] (goto: $here)]
    
    [Examine the leaflet]<getleaflet|
    (click-replace: ?getleaflet)[(set: $leaflet to true)[Description of leaflet.] (goto: $here)]
    
    (if: $ticket is true and $ledger is true and $leaflet is true)[Content appears]
    

    The first line gets the name of the current passage in order to be able to redisplay it.

    2: Place the check into a (live:) macro so it is run periodically
    {(set: $ticket to false)
    (set: $ledger to false)
    (set: $leaflet to false)
    }
    
    [Examine the paper ticket]<getticket|
    (click-replace: ?getticket)[(set: $ticket to true)[Description of ticket.] ]
    
    [Examine the ledger]<getledger|
    (click-replace: ?getledger)[(set: $ledger to true)[Description of ledger.] ]
    
    [Examine the leaflet]<getleaflet|
    (click-replace: ?getleaflet)[(set: $leaflet to true)[Description of leaflet.] ]
    
    (live: 1s)[(if: $ticket is true and $ledger is true and $leaflet is true)[Content appears(stop:)]]
    

    The (stop:) macro is there so the live doesn't keep running after the conditions are true.
  • Thanks, that makes sense.
Sign In or Register to comment.