Modifiying Characteristics of a character chosen

Twine Version: 2.3.14
Story Format: Harlowe 3.2.2

I am attempting to create a passage which pulls a character’s datamap from the $characters array, modifies some of the values, then feeds the new information back into the original datamap.

The idea is that the player is supposed to choose a target at their discretion, change them, and have it be reflected in the rest of the story. I am able to pull the datamap from the array and assign it to a temporary variable on the page I can modify those values, but I cannot figure out how to feed the new information into the original datamap. Here is the code I’m trying to make work:

(set: _target to (find: _character where _character's name contains $target, ...$characters))
(set:_height to _target's 1st's height, _weight to _target's 1st's weight)
You point the Shrink Ray at $target and activate it.  As a result, $target is now (if:$metric is true)[10 cm shorter and 5 kg lighter(set:_height to it-10, _weight to it-5)](else:)[5 in shorter and 10 lb lighter(set:_height to it-5, _weight to it-10)]
(set: _target to (dm: "name", $target,"height", _height, "weight", _weight))(move: _target into (find: _character where _character's name contains $target, ...$characters))
(link-goto:"Return", $lastPassage)

Is this even possible in Harlowe

Personally I would of used a DataMap like the following to store your $characters information, because it would of made it a lot easier to access and update each Character.

(set: $characters to (dm: 
	"Jane", (dm:
		"name", "Jane",
		"height", 10,
		"weight", 10
	),
	"John", (dm:
		"name", "John",
		"height", 11,
		"weight", 11
	)
))

But to answer your question, if I assume that the values of relevant variables looks something like the following…

(set: $characters to (a:
	(dm:
		"name", "Jane",
		"height", 1,
		"weight", 1
	),
	(dm:
		"name", "John",
		"height", 1,
		"weight", 1
	)
))
(set: $target to "John")
(set: _target to (dm: "name", "John", "height", 2, "weight", 2))

…then you can use a (for:) macro combined with a (range:) macro to determine the index of the specific Character element in the Array, and then use that index to replace that element with the updated Character.

(for: each _index, ...(range: 1, $characters's length))[
	(set: _character to $characters's (_index))
	(if: _character's name contains $target)[
		(set: $characters's (_index) to _target)
	]
]

And if you’re really adventurous, you could use the new (macro:) macro to transform the above solution into a Custom Macro, but I’ll leave that adventure for you to experience.

warning: For those that use both Custom Macros and the (save-game:) family of macros.

The definition of a Custom Macro is stored within a Story Variable, which in turn are stored within the variable state of any ‘save’ created during the play-through of the project…

If you update the definition of a Custom Macro between releases of your project then any ‘save’ created in a previous release will contain the older version of that Customer Macro’s definition, and the loading of that ‘save’ will cause the new definition to be overwritten by the old definition.

I changed it to a datamap for ease of use. However I am not yet well-versed in coding, so I am struggling to implement the modifications. What would I have to change from your examples in order to use datamaps?

Assuming the relevant variables are initialised something like the following…

(set: $characters to (dm: 
	"Jane", (dm:
		"name", "Jane",
		"height", 1,
		"weight", 1
	),
	"John", (dm:
		"name", "John",
		"height", 1,
		"weight", 1
	)
)) 
(set: $target to "Jane")
(set: $metric to true)

…then your original example would look something like the following…

{
(set: _target to $characters's ($target))
(set:_height to _target's height, _weight to _target's weight)
You point the Shrink Ray at $target and activate it.  As a result, $target is now 
(if: $metric)[
	10 cm shorter and 5 kg lighter
	(set: _height to it - 10, _weight to it - 5)
]
(else:)[
	5 in shorter and 10 lb lighter
	(set: _height to it - 5, _weight to it - 10)
]
(set: $characters's ($target) to (dm: "name", $target, "height", _height, "weight", _weight))
}

note: I added some indentation and extra line-breaks, as well as Collapsing whitespace markup, to make the above a little more readable and to suppress the likely unwanted blank lines being generated by the (set:) macro calls and my formatting.

Thanks, that did it