Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

checking for specific object within array

Twine 2.1.1
Sugarcube 2.14.0

I have recently switched to Sugarcube from Harlowe and after watching some videos on youtube and implementing the inventory system from the Twine Wiki, i have run into a problem.
I want to be able to check if i have a specific object in my inventory array, but what works for values does not work for objects.

I'm new to programming in general and the idea at the moment is to prevent the player from picking up the same items twice.
<<if $inventory.indexOf("$sword") == -1>>
<<linkreplace"Pick up the sword">>//You've picked up the sword!//<<addToInv $sword>><</linkreplace>><<else>>There used to be a sword here.

The object is successfully added to the inventory and i can print it and its values just fine, but when i return to the same passage where i got it, i can pick it up once more.

The code works as intended if it's just "sword" instead of "$sword".

I'm probably going about this all wrong, but i have not been able to find anyone else doing something similar so i turn to you. Does anyone know how to make this work?


Sign In or Register to comment.