Twine Version: 2.3.5
Story Format: Harlowe
Building an inventory, I have a main variable to hold all items, and two vars to store items the player is using like swords, clothes, etc. The player must use specific items, example: left hand and right hand.
(set: $invent to (a:)) <-- the main inventory with all collected items -->
(set: $e_lh to (a:), $e_rh to (a:)) <-- left hand and right hand slots -->
A weapon would be set like this:
(set: $e_sword to (a:"Sword","rh"))
So it’s a sword that can be used only in your right hand.
To get the item, I’m using:
(link: "Get sword")[(set: $invent to it + (a:$e_sword ))]
This way I can check my items in a “inventory” passage. But I need to equip each item in the correct slot (like head, right hand, left hand, etc), so:
(link-repeat:"Equip")[
(if: $invent's 1st's 2nd is "rh")[ <!-- if first item is made for rh... -->
(move: (a:$invent's 1st) into $e_rh) <!-- move it to rh -->
] (else-if: $invent's 1st's 2nd is "lh")[ <!-- else, if its for lh... -->
(move: (a:$invent's 1st) into $e_lh) <-- move to lh and so on -->
]
]
I was thinking if it’s possible to reduce the last part like this getting rid of all those if-else blocks (just a template):
(link-repeat:"Equip")[
(move: (a:$invent's 1st) into $e_X) <!-- where X is the value taken from $invent's 1st's 2nd, i.e., rh or lh -->
]
Is it possible or is there any similar approach for the same result? Thank you very much!