Harlowe 3.1 Array for function working but showing error- Please help!

Please specify version and format if asking for help, or apply optional tags above:
Twine Version: 2
Story Format: 3.1

Hi guys, super new to coding so don’t really know what is happening. I am making an inventory and have programmed it to link to another page with the description. It’s working but giving me an error message. Am I missing something really obvious. And is there a way to turn off error messages when it goes into play mode?

(print: $cyclop’s “name”): Str (print: $cyclop’s “strength”), Int (print: $cyclop’s “intelligence”), Dex (print: $cyclop’s “dexterity”), Mag (print: $cyclop’s “magic”), Hp (print: $cyclophealth)
Items:(for:each _item, …$cyclopinv)[(link:"(print: _item’s name)")[(set:$selecteditem to _item)(goto: “Item Description”)]]( (remaining strength (print: $cyclopcarry))

(link-goto: “Return”, (history:)'s last)

What is produced:

Statistics and Inventory

Uno Bollocks: Str 92, Int 23, Dex 32, Mag 7, Hp 150
Items:You can only access position strings/numbers (‘4th’, ‘last’, ‘2ndlast’, (2), etc.) or slices (‘1stTo2ndlast’, ‘3rdTo5th’), ‘length’, ‘any’ and ‘all’ of the string “”, not the string “name”.►rope( (remaining strength 77)

Return

I think it’s this part that’s throwing the error:

link:"(print: _item’s name)"

It should be one of the following:

link:(print: _item’s "name")

or

link:'(print: _item’s "name")' 

or

link:"(print: 'name' of _item)"

I don’t use Harlowe and I’m not sure how it does strings within strings. Hopefully one of those options will do the trick for you.

I don’t think there’s a way turn off error messages. The goal is to just not have errors. Heh.

Please use the Preformatted text option (in the comment field’s toolbar) when including a code example in your comment, as it stops the forum’s software from converting standard single & double standard quotes (' and ")into invalid Curly Typographical equivalents (’ and ").

You don’t include an example of the contents of your $cyclopinv Array, so I assumed it is something like the following in the test project I create…
(likely each of your Data-Map instances have more properties that just “name”)

(set: $cyclopinv to (a: (dm: "name", "aaaa"), (dm: "name", "bbbb"), (dm: "name", "cccc")))

I tested the following code and it worked successful…

(set: $cyclop to (dm: "name", "zzzz", "strength", 10, "intelligence", 11, "dexterity", 12, "magic", 13))
(set: $cyclophealth to 14, $cyclopcarry to 15)
(set: $cyclopinv to (a: (dm: "name", "aaaa"), (dm: "name", "bbbb"), (dm: "name", "cccc")))

(print: $cyclop's "name"): Str (print: $cyclop's "strength"), Int (print: $cyclop's "intelligence"), \
Dex (print: $cyclop's "dexterity"), Mag (print: $cyclop's "magic"), Hp (print: $cyclophealth)
Items: (for: each _item, ...$cyclopinv)[{
	(link: "(print: _item's name)")[
		(set: $selecteditem to _item)
		(goto: "Item Description")
	]
}]( (remaining strength (print: $cyclopcarry))

(link-goto: "Return", (history:)'s last)

warning: Whenever the contents of either an Array or a Data-Map is updated the (set:) macro clones the original collection object and then updates the new clone, this process breaks object referential integrity. Which is a fancy way of saying if two variables were referencing the same object before the update the update then those two variables will be referencing different objects after that update. The following to test case demonstrate the above mentioned behaviour.

Updating the name of the Array element…

(set: $cyclopinv to (a: (dm: "name", "aaaa"), (dm: "name", "bbbb"), (dm: "name", "cccc")))
(set: $selecteditem to $cyclopinv's 2nd)
Original Array: (print: ($cyclopinv's 2nd)'s "name")
Original selected: (print: $selecteditem's "name")

(set: ($cyclopinv's 2nd)'s "name" to "dddd")
Changed Array: (print: ($cyclopinv's 2nd)'s "name")
Unchanged selected: (print: $selecteditem's "name")

Updating the name of the selected item.

(set: $cyclopinv to (a: (dm: "name", "aaaa"), (dm: "name", "bbbb"), (dm: "name", "cccc")))
(set: $selecteditem to $cyclopinv's 2nd)
Original Array: (print: ($cyclopinv's 2nd)'s "name")
Original selected: (print: $selecteditem's "name")

(set: $selecteditem's "name" to "dddd")
Unchanged Array: (print: ($cyclopinv's 2nd)'s "name")
Changed selected: (print: $selecteditem's "name")

Hi Greyelf,

Thank you for the help, but it’s still giving the same error message. I don’t know if it is because I am adding arrays together?

This is my start up, am I allowed to put the $rop in the array if it represents a datamap?

{
<!-- Characters -->
(set: $cyclop to (datamap:"name", "Uno Bollocks", "title", "cyclops", "description", "This one-eyed gentle giant has a big heart and all they ever wanted was a nice group of friends. They also happen to be immune to fire.", "strength", 92, "intelligence", 23, "dexterity", 32, "magic", 7) )
(set: $cyclophealth to 150)
(set: $cyclopcarry to 92)


<!-- Items -->
(set: $rope to (datamap:"name", "rope", "description", "A strong sturdy rope of about 10m.", "pickup text", " put the rope their bag.","weight", 15))


<!-- Set items -->
(set: $communalitems to (a:$rope))
(set: $cyclopinv to (a:""))

<!-- Set variables -->
(set: $selecteditem to "")
(set: $previouspassage to "")
(set: $selectedperson to "")


}

I then add the $rope to the cyclopinv and out of the communalinv. Is this ok?

Who should carry the (print:$selecteditem's "name") ? It weighs (print: $selecteditem's "weight")
(if:$cyclopcarry >= $selecteditem's "weight")[(link: "Uno Bollocks")[(set: $selectedperson to $cyclop)(set: $cyclopinv to ($cyclopinv + (a: $rope)))(set:$cyclopcarry to ($cyclopcarry - ($selecteditem's "weight")))(set:$communalitems to ($communalitems - (a:"$rope")))(goto:"Item Acquired")]]

Then I’m using your code for the inventory page.

It’s still producing this:


So the link works like it should but it still has an error message.

I’m sorry that my code is probably garbage, this is my first project and I’ve probably bitten off more than I can chew.

Thank you

note: Your previous examples don’t include the initialisation of the $cyclopinv Array variable, I will assume looks something like.

(set: $cyclopinv to (a:))

When trying something new it is generally a good idea to create a simple test case to see if the code works as expected.

Take the case of the (set: $communalitems to ($communalitems - (a: "$rope"))) line of code that you are using to remove an specific Data-Map object reference from an Array.

(set: $rope to (datamap: "name", "rope", "description", "A strong sturdy rope of about 10m.", "pickup text", " put the rope their bag.","weight", 15))\
(set: $communalitems to (a: $rope))\
Before Delete Length: (print: $communalitems's length)

(set: $communalitems to it - (a: "$rope"))\
Quoted Delete Length: (print: $communalitems's length)

(set: $communalitems to it - (a: $rope))\
Unquoted Delete Length: (print: $communalitems's length)

If you run the above test case you will see that the Quoted Delete doesn’t do anything, because there is no instance of that String value within the Array.

You can use a similar test case for the (for:) macro…

(set: $cyclopinv to (a:))\
(set: $communalitems to (a: $rope))\
(set: $cyclopinv to ($cyclopinv + (a: $rope)))\
(set: $communalitems to ($communalitems - (a: $rope)))\
List Cyclop Inv: {
(if: $cyclopinv's length > 0)[
	(for: each _item, ...$cyclopinv)[
		(print: _item's "name")
	]
]
(else:)[Empty]
}
After Length: (print: $communalitems's length)