I receive an error when adding variable to an array, but it does add it and nothing seems to brake

Twine Version: 2.8.1.0
Harlowe Version: 3.3.8

Hey everyone,
So, I receive an error regarding the same line of code, but the line of code actually works. And it freaks me out. Maybe this is an error that I will see only in some circumstances or sth like that, I’d like to know what it thinks is wrong.

At some point in my game I want to show a random story from an array of stories.
Each story is a separate sequence of nodes with dialog options etc. So I have this (with a start-up tag):

(set: $coinStory to (display: "coin-story"))
(set: $eelStory to (display: "eel-story"))
(set: $writingPoetryStory to (display: "poetry-story"))

(set: $generalStories to (a: 
$coinStory,
$eelStory))

I want some stories to be accessible from the array of stories only after player encounters some events.
During the game player meets a certain character, and inside that node I have a function that should add a new story to the array of stories, which may be called at some point later in the game. That’s what I do, and I always receive an error:

(set: $generalStories to it + (a: $writingPoetryStory))

I have a checklist below that says (print: $generalStories), and I see that new [A (display:) command] was added to it. And later it the game it prints the writing poetry story as it should.

Error message:

An internal error occurred while trying to run (set: $generalStories to it + (a: $writingPoetryStory)).The error was “undefined has no properties”. If this is the latest version of Harlowe, please consider reporting a bug (see the documentation).

Weird thing is, I can delete variables from an array in the same manner and I do not receive error messages. I have this at some point and it works:


(if: $generalStories contains $thisGeneralStory) [(set: $thisGeneralStory to $generalStories's random)]
(else:) [(set: $thisGeneralStory to $generalStories's random)]
(set: $generalStories to it - (a: $thisGeneralStory))

I tried changing display command to print and to goto, received either the same error or the following error:

An internal error occurred while trying to run (set: $generalStories to it + (a: $writingPoetryStory)).The error was “e is undefined”. If this is the latest version of Harlowe, please consider reporting a bug (see the documentation).

No idea what’s ‘e’ here.

Thank you and sorry if it’s poorly written.

Just curious, when I first looked at your code, my first inclination was to store the passage names in an array, but not the passages themselves. Then you would pull a passage name from the array and use (display:) with the string value from the array. Is there a reason to store all passage content in the array?

1 Like

hey, thank you very much, it worked! no error message and it looks neater. I didn’t realise I could just pack the passages’ names and call them later.

for anyone who might read it in the future, that’s the change:

(set: $generalStories to (a: 
"coin-story",
"glowing-eel-story")

(set: $generalStories to it + (a: "writing-poetry-story")

(set: $currentstory to (display: $generalStories's random)
2 Likes

Glad you got it working, but I’d like to note that it looks a lot like you are re-inventing (storylet:).

Have you checked out the storylet macros and found that they don’t fit your needs?

1 Like

hey! thank you for mentioning storylets to me, that’s new, and you’re probably right about the re-inventing.
i’d like to have grouped stories, be able to withdraw a random story from any group at any point, and never withdraw the same story twice.
i see that withdrawing a random thing and filtering using tags is possible.
i found a mention of the (history:) macro used to make storylets unrepeatable, but i haven’t figured out how exactly this is done.
i’ll keep exploring this thing.