0 votes
by (120 points)
Whenever I try to use IndexOf, I get the following error

"Error: <<if>>: bad conditional expression in <<if>> clause: Cannot read property 'indexOf' of undefined"

This is an example of the code that's returning that.

<<if $inventory.indexOf("Sasha") == 0>>I can see Sasha, holding you, wiping your face, asking over and over 'what did you do? what did you do?!'<<endif>>

Here's where that inventory item is added

<<addToInv "Sasha">>

This worked back in 2016 when I first created the story.

I'm using SugarCube 1.0.35

1 Answer

0 votes
by (159k points)

That error message is stating that the $inventory story variable hasn't been initialised (assigned a value).

Check where in your project you are setting the $inventory story variable to an Array, ideally that should be within your project's StoryInit special passage which is where all your story variables should be assigned their default values.

warning: The 1.x series of SugarCube quite old and is no longer being developed, I strongly suggest you switch to using the 2.x series of the story format.

...