Hi.
I'm trying to write a game so that each character is an object variable. The objects get pushed into various location arrays so the game knows where the characters are, and their stats and inventory remain consistent.
Eg:
<<set $ralph = {name: "Ralph", hp: 10, inventory:[]}>>
<<set $jane = {name: "Jane", hp: 10, inventory:[]}>>
<<set $player = {name: "Playername", hp: 10, inventory:["key", "sword"]}>>
<<set $village = []>>
<<set $village.push($ralph)>> /* ralph is placed in the village */
Then the player can interact with them, and there's a passage for each type of interaction. So I have a variable that holds a reference to the character's object:
<<set $currentCharacter to $ralph >>
Then in the Fight passage, $currentCharacter is used for the interaction, so that the passage can work on any character.
The problem is, the references aren't working as I understand they should be. In the above examples, from what I can tell, it's only a copy of $ralph that gets added to the village, and only a copy of $ralph is set as $currentCharacter. This means that only the copy gets changed, and the original $ralph remains unchanged.
What I mean is probably best expressed by this story file that demonstrates what I'm trying to do and you can see how it fails (try changing character's HPs and switching characters and you'll see what I mean).
download demo file here
If you have any idea how to get these to reference properly, I'd really appreciate it.