Howdy, Stranger!

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

list from array styling

I created an array and it displays the objects of the array in a list separated by commas as shown in screenshot. How do I style the list so the items appear one underneath the other and without the commas? Thank you.


  • Could you share your code, please? What story format are you using?
  • Here is the datamap code:

    <!-- put Farmer Card info into Datamap -->
    (set: $farmer to (datamap: "name", "The Farmer Card", "description", "Farmers farm for the love of farming. They love to watch and nurture the growth of plants. They love to live in the presence of animals. They love to work outdoors. They love the weather, maybe even when it is making them miserable. - Wendell Berry.", "collect", "collected the farmer card.", "isCollected", false))

    (set: $collected to "")

    (print: $farmer's name)

    (print: $farmer's description)

    <!-- Provide link to collect card. Set it to true and put into array. -->
    (if: $farmer's isCollected is false)[(link: "Collect Farmer Card")[(set: $selectedItem to $farmer)(set: $farmer's isCollected to true)(set: $userCards to (array: "Farmer Card"))(goto:"The Gourmet")]]

    So you can see the array above and it puts the datamap Farmer Card into the array. Then in another passage, I call the item in the array:

    (print: $userCards)

    But this gives me the cards in a one line list: Farmer Card, Gourmet Card, etc..

    I want it to look like:

    Farmer Card

    Gourmet Card

    How do I style the code to get this? i am using Harlowe. Thank you!
  • i am using Harlowe
    It is important to always state which story format you are using when asking a question because it influences the answers given.
    When including code examples could you please wrap them in code tags, it is the C button in the toolbar above the text field. It makes code easier to read and looks like the following:
    (set: $collected to "")

    You can use the Javascript Array join function to convert your array into a formatted string, using \n symbols to insert line-breaks. Try the following:
    (set: $userCards to (array: "Farmer Card", "Gourmet Card"))
    (print: $userCards.join("\n\n"))

    In your original example the (link:) macro contained a (set: $userCards to (array: "Farmer Card") statement which would replace the current value of $userCards with a new array containing "Farmer Card", if instead you wanted to add a new item to the $userCards variable you would do the following:
    (set: $userCards to it + (array: "Farmer Card"))
    ... the above assumes that you have initialized the $userCards variable in your startup tagged passage like so:
    (set: $userCards to (array:))
Sign In or Register to comment.