Need a little help on SugarCube v2 Inventory

Twine Version: 2.3.16
Story Format: SugarCube 2.36.1

Hello there,

I’m trying to set up an inventory system. I’ve gotten to a point where I can add to my $inv and the descriptions show up in my inventory passage. However, I’m struggling to figure out how to make them mean anything for instance…
In my StoryInit I have pie as…

<<set $pie to "a delicious dessert">>

Let’s say someone gives me a pie…

<<set $inv to $inv + $pie>>

My inventory passage which is set up as "In your inventory you have : $inv "
That now displays “a delicious dessert”

My question is in another passage. I want a dialogue that says “Give him the pie”
Only if my $inv actually has that pie, and then have it removed from inv.

What would that look like as far as code?

Appreciate any help

1 Like

So you can do tricky things with arrays. I know they are useful but that makes my head hurt.

What I did in Cursed Pickle of Shireton was limit the stuff the player could pick up. You can define variables for each thing.

$hasSword = true
$hasBlueKey = false

Then on your inventory page

<<if $hasSword eq true>>You're carrying a sword.<</if>>
<<if $hasBlueKey eq true>>You've got the blue key.<<else>>You need to find the blue key.<</if>>

In your passage, you can check stuff like.

You see a blue door.
<<if $hasBlueKey eq true>>
[[Open the door with the blue key.|blueroom][$hasBlueKey to false]]
It's got a blue keyhole that would seem to require a blue key.
1 Like

You’re a wizard.

That worked for me.
Thank you so much. :heart:

1 Like