Howdy, Stranger!

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

How do I remove variables from an array in Harlowe?

edited May 2015 in Help! with 2.0
So let's say I make an array of strings. Let's say it's called $candy, and contains "laffy" and "taffy".

Calling "$candy's 1st" gives you "laffy", of course. However, I would like to remove "laffy", in such a way that calling "$candy's 1st" gives you "taffy".

How do I do this? I see the occasional mention of (remove: ) but that doesn't seem to exist in Twine 2.

Comments

  • If you look at the Harlowe documentation you will see a (subarray:) macro, this is what you use to remove an element and then resize an array.

    The format of the macro is (subarray: array, start_index, end_index), so for your example it would be:
    (set: $candy to (subarray: $candy, 2, $candy's length))
    

    Test Code:
    Initialize the Candy Array
    (set: $candy to (array: "laffy", "taffy"))
    length: (print: $candy's length)
    1st: (print: $candy's 1st)
    2nd: (print: $candy's 2nd)
    
    
    Use SubArray macro to remove first element from Array
    (set: $candy to (subarray: $candy, 2, $candy's length))
    length: (print: $candy's length)
    1st: (print: $candy's 1st)
    2nd: (print: $candy's 2nd)
    
Sign In or Register to comment.