Adding Items to Array Not Working

Twine 2.8.1 | Harlowe 3.3.8

I’ve read the Twine Cookbook and the Harlowe 3.3.8 Manual and based on what I’ve read, the following code should work:

(set: $items to + (a: 'jacket', 'waterbottle', 'flashlight', 'med kit'))
(set: $parray to + (a: 'dimensional storage'))

But when I run it, I get the error:

I can only multiply numbers, not an array (with the string “jacket”, the string “waterbottle”, and 2 other items).
I can only multiply numbers, not an array (with the string “dimensional storage”).

What am I missing? Any suggestions?
Much appreciated!

You’re just missing two little characters:

(set: $items to it + (a: 'jacket', 'waterbottle', 'flashlight', 'med kit'))

Unfortunately, that returns the error:

The number 0 isn’t the same type of data as an array (with the string “jacket”, the string “waterbottle”, and 2 other items)

Which is extra weird, because $parray worked with that change :S

It sounds like you’re initializing $items as a number wherever you first set it (which is not in the code you’ve posted here). Try setting it to a blank array initially.

The original is just an empty array

(set: $item to (a:))

Did I mess that up somehow?

If that’s an accurate copy of what’s in your project, then the issue is that you’re intializing the variable as $item (without an s) and then calling the nonexistent variable $items (with an s) when you want to add stuff to it.

1 Like

/facepalm/ thank you so much!

2 Likes