Howdy, Stranger!

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

Print every item in array with SugarCane? (Twine 1.4.2 on Mac OS Yosemite)

My game has ending badges. I've set up arrays to keep track of what badges are unlocked. These are images, and I've figured out how to save them to an array. What I'm not finding is the syntax for pulling them out of the array, to display them. <<print>> gives me a list with commas, which I don't want. I'm not seeing a built-in function, so I'm poking into building my own, but is there an easier way to do this?


  • Sugarcane or SugarCube? You say one, but capitalize it like the other—and, bizarrely, no one can keep them straight anyway. You should also give the story format's version as well, because that can make a difference.

    Regardless. That should be a fairly easy task. That said, however, without knowing a) how the images are stored within the array and b) how you want the final output formatted, save that you do not want a comma separated list, it's difficult to offer specific suggestions.

    As but one example. If they're stored as image markup that you simply need to print, then something like the following should put you on the right track: (assume that the array is named $badges)
    → As one one line, which the browser may break as necessary.
    <<print $badges.join("")>>
    → Each on its own line.
    <<print $badges.join("\n")>>
    → (same)
    <<print $badges.join("<br>")>>
    SEE: <Array>.join() method.
  • Sugarcane, in Twine 1.4.2. When I tried switching to SugarCube 2, the game wouldn't display or run, even if I cleared out the CSS.

    My array is $badges_list, and I do just want them to print. I have a flexbox set up to handle how they display, so that's what I needed. Thanks!
Sign In or Register to comment.