Howdy, Stranger!

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

Problems with conditional links to passages (Harlowe)

edited June 2016 in Help! with 2.0
Alright, so this is my first twine game, and anyone who bothers to check will can see that I made this account a sole 5 minutes ago, but I'm really at a loss here. But don't worry, I've lurked enough to not be a complete pain.

I'm using Twine 2 with Harlowe because as it will soon become apparent, i'm really not a coding expert. At all. Most of what i've done has been through osmosis of various tutorials, and...I'm having a lot of problems, But I just go with this one first.

In the game i am creating, there's a fair bit of "open world exploration", as in there's a passage that acts as a hub (The Pod), at three main locations to visit (The Docks, The Forest, The Village). What I'm trying to do is create conditions that must be met in order for certain passages to be read for the player to proceed. The scenario is pretty much: Player must meet 3 conditions, "accessed_village" + "accessed_dock " + "accessed_forest" to 'notice something they missed when previously at an area and have the option to go to a previously unseen passage. to do this, i'm creating a-not-really item that is added to the players $inv array, so that when the conditions are met it shows up.
it looks like this:

(set: $inv to $inv + (a: "accessed_dock"))

repeat in two more locations (yes, i've checked spelling) annnnd:

(if: $inv contains "accessed_village" + "accessed_dock " + "accessed_forest")[Oh, and there's a dog wearing a scarf watching you from under cafe table.]

Now- I have created something similar: alternate text based on what item the player chose to take earlier in the game, using stat values (picking up object put the item into the $inv array, as well as a value for a stat (the game has three stats that effect stuff, basic if/elseif/elseif ) AND THAT WORKED. The array method does not.

So if you've gotten through all of that, my question is, how can I use arrays to if/else conditions, so the player is able to "unlock" new dialoge by preforming tasks (which I could assign values i suppose), or having 'items' in the $inv array?

Comments

  • Oh I didn't mention the error, It just doesn't show up

    Now as mentioned, this is one of....many problems with my coding. Any suggestions are appreciated!
  • Harlowe's contains operator searches for a single item in an array and returns a Boolean value of true or false depending on if it was found or not, so what your existing (if:) example is currently trying to do is:

    a. See if String "accessed_village" is within the array. (Boolean true or false)
    b. Add two String values ( "accessed_dock " + "accessed_forest") to the Boolean

    Unfortunately the contains operator does not support searching for an array of values, as demonstrated by the following test:
    (set: $list to (array: "A","B","C","D"))
    (set: $items to (array: "A","C"))
    
    (if: $list contains $items)[The list contains the items. ]
    (else:)[The list does not contains the items. ]
    

    There is a way to achieve the result you want but using array subtraction and checking the length (number of elements in) of the result:
    (set: $list to (array: "A","B","C","D"))
    
    (set: $items to (array: "A","C"))
    (set: $result to $items - $list)
    (if: $result's length is 0)[The list contains the items.]
    
    ''Same test as above but using this time $items contains an element not in the list, note the usage of the greater than > operator instead of is''
    
    (set: $items to (array: "A","C","E"))
    (set: $result to $items - $list)
    (if: $result's length > 0)[The list does not contains the items. 2]
    result: $result
    

    The above two examples used extra variables to store the items and the result of the subtraction, this was both for readability sake and to help with debugging.

    You can do the same process using only the $list variable:
    (set: $list to (array: "A","B","C","D"))
    
    (if: ((array: "A", "B") - $list)'s length is 0)[The list contains the items.]
    
    (if: ((array: "A", "B", "E") - $list)'s length > 0)[The list does not contains the items.]
    
  • Thank you so much for the response, I see now why it wasnt working, and your solution makes a lot more sense than anything else ive seen so far.

    However in the end, i ended up making the decision to change what the game required the player to do to advance (instead of 'areas accessed', its now 'characters introduced' as i already had a single use passage set up (you dont know someones name the first time you meet them!) so ive created an incresing varible that must be met, instead of creating a list.

    If anything similar this problem comes up in the future, I'll definetly be using your solution!! Again, thank you so much!
Sign In or Register to comment.