Howdy, Stranger!

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

Harlowe Loops?

Anyone have an idea if this can be done with Harlowe? Basically, I want to create a series of DataMaps that contain information about my objects, but I'd like to store that information in an array. These objects will contain all the same fields. At various points in the game, I'd like to print out certain fields or maybe add them and so forth.

Currently, I'm not finding anyway to iterate through that array outside of hardcoding each individual index. Is there a way do this?

Any help is appreciated.

Comments

  • Am I the only one who thinks it is weird that you can't iterate through a collection? It seems to undercut the usefulness of an array if I can't iterate through it.  Granted, I should be using a more developer friendly format, but I'd like to know if this is possible with Harlowe since it is the default format.

    I'm actually writing an article on Twine and I'd like to make sure I have this correct. Again, any thoughts are appreciated.
  • note: Although the following solution works it may not be a good solution to the problem.

    It is possible to use a combination of a hook, (live:) and (append:) to do what you want.

    WARNING: Always remember to include a way to (stop:) your (live:) macros, otherwise they keep triggering.

    (set: $list to (array: "A","B","C","D","E"))
    (set: $index to 0)
    (set: $length to $list.length)

    Display List: $list
    Number of items in List: $length

    [Looping:]<output|

    (live: 20ms)[(set: $index to it + 1)(append: ?output)[<br>Item $index: (subarray: $list, $index, $index)](if: $index is $length)[(stop:)]]
    A breakdown of the (live:) macro:

    /* Do the following every 20 milliseconds until told to (stop:) */
    (live: 20ms)[

    /* Increment the index, which is used to access each item in the $list array. */
    (set: $index to it + 1)

    /* Append the next item description to the output hook, using a <br> to add a new-line */
    (append: ?output)[
    <br>Item $index: (subarray: $list, $index, $index)
    ]

    /* If we have printed all the items then stop the (live:) macro so it does not loop forever! */
    (if: $index is $length)[
    (stop:)
    ]
    ]
    note: This Harlowe patch states that you should be able to access array items using a numberic expression but I could not get it to work!
Sign In or Register to comment.