Twine: 2.92, Sugarcube 2.37
Hi all,
Slowly transitioning my story from Harlowe to Sugarcube and I’m having some trouble with .includes and moving objects between arrays and List boxes.
Could someone clarify the syntax for what I’m trying to do below. Which is move stuff between arrays and at some point have an if statement to see whether an array contains a specific object by name. I could do all this stuff in Harlowe but now I’m struggling a bit.
Thank you so much.
<<set $desk to []>>
<<set $inventory to []>>
<<set $inventory to [
{ name: "Saw", itemType: "Tool", weight: 2, cost: 5},
{ name: "Ruler", itemType: "Stationery", weight: 1, cost: 1},
{ name: "House key", itemType: "Key", weight: 1, cost: 1}
]>>
<<set $desk to [
{ name: "Pencil", itemType: "Stationery", weight: 1, cost: 1},
{ name: "Eraser", itemType: "Stationery", weight: 1, cost: 1},
{ name: "Hammer", itemType: "Tool", weight: 3, cost: 1}
]>>
<br>
On desk:
<br><<print $desk[0].name>>
<br><<print $desk[1].name>>
<br><<print $desk[2].name>>
<br>
<br>Carrying:
<br><<print $inventory[0].name>>
<br><<print $inventory[1].name>>
<br><<print $inventory[2].name>>
<br>
<<link "<br>>Choose item from desk">>
<<set $desk.delete($itemChoice)>>
<<set $inventory.push($itemChoice)>>
<</link>>
<<listbox "$itemChoice" autoselect>>
`<<optionsfrom $desk>>`
<</listbox>>
<<link "<br>>Place item on desk">>
<<set $inventory.delete($itemChoice)>>
<<set $desk.push($itemChoice)>>
<</link>>
<<listbox "$itemChoice" autoselect>>
`<<optionsfrom $inventory>>`
<</listbox>>
<br>
<<if $desk.includes ("Pencil")>>
<br>The pencil is on the desk.
<</if>>