Hello everyone,
Rundown: I'm making a twine rpg and a core feature of my the game is being able to transfer gold and items between characters. I implemented a simple custom saving system that autosaves into a specific save slot using the following code (the save slot is chosen by the player at the start of the game):
<<if $saveslot is 1>>
<<remember $S1_playername to $playername>>
<<remember $S1_playerLVL to $playerLVL>>
<<remember $S1_playerclass to $playerclass>>
<<remember $S1_player_race to $player_race>>
<<script>>Save.slots.delete(0); Save.slots.save(0)<</script>>
<</if>>
I then implemented a common "stash" that enables the player to transfer gold between saved characters using a simple <<remember>> macro, and forcefully saving the game immediately after executing a gold transfer (to prevent unlimited gold duping).
<<remember $stash_gold to $stash_gold + $deposit_gold>> // $deposit_gold is a value inputted by the player//
<<set $gold to $gold - $deposit_gold>>
<<autosave>> // This runs the above macro //
The following code works beautifully. I was able to both deposit and withdraw gold using the common variable $stash_gold.
Now my primary problem is making the same thing happen with an array of objects. Simply put, my RPG has a lot of equipment: Swords, Shields, Armor, etc... and each is an object with its own properties. All these items are stored in an $equipment array. When I try to replicate the stash_gold method above, i.e. using the following code:
<<set _temporary to $equipment.pluck(0,0)>>
<<remember $stash_equipment.push(_temporary)>>
I successfully transfer said Object into the $stash_equipment array. Upon restarting my browser and using the "Debug" feature to view the variable library, I still see the object and all its properties in the $stash_equipment array. HOWEVER, when I load another saved character, the array simply VANISHES.
I checked my entire game's code thoroughly and I did not find any code snippet which modifies the $stash_equipment array in any way except the following code at the top of the "Stash" passage:
<<if ndef $stash_equipment>><<set $stash_equipment to []>><</if>>
Sorry for being long winded and very newbie-ish, but I've been wrecking my brain trying to figure out a solution to this problem. Am I doing it the wrong way? Can the <<remember>> macro remember Objects within arrays?
Edit: Here's a snippet of my "Load Game" code:
<<click "Load Slot 1">>
<<stopallaudio>>
<<script>>Save.slots.load(0)<</script>>
<</click>>\
\
<<if $saveslot1 is 1>> | <<print $S1_playername>>, Level <<print $S1_playerLVL>> <<print $S1_player_race>> <<print $S1_playerclass>>, <<print $S1_difficulty>> <<print $S1_gamemode>> | <<link "Delete">><<script>>Save.slots.delete(0)<</script>><<remember $saveslot1 to 0>><<goto "Load Game">><</link>><<else>> | Empty |<</if>>