It looks like you're new here. If you want to get involved, click one of these buttons!
<<silently>> <<set $roomWidth = 16>> <<set $roomLength = 12>> <<set $crateOpen = "{{{>> }}}In the northwest corner, there is a small crate (you opened it earlier).">> <<if $cave_room1_crate == "Open">><<replace "#crateText">>$crateOpen<</replace>><</if>> <</silently>> {{{>> }}}You find yourself in a small room. The dimensions of the room are <<print $roomWidth>> feet by <<print $roomLength>> feet. {{{>> }}}Exits are [[north|cave_room6]] and [[west|cave_room2]]. <span id="crateText">{{{>> }}}In the northwest corner of the room, there is a small <span id="crate"><<click "crate">><<replace "#crate">>crate<</replace>><<replace "#output">>Inside the crate, you find a <span id="item">small silver key</span>, a large <span id="keyItem">Yellow Key</span>, and <span id="gold">25 gold</span>.<</replace>><<set $playerScore +=25>><</click>><<set $cave_room1_crate = "Open">></span>;</span> next to it, a medium-sized <span id="chest"><<click "chest">><<replace "#chest>>chest<</replace>>.<</click>>.</span> <span id="torch">A <<click "torch">><<replace "#torch">><</replace>><<replace "#output">>You take the torch from the wall.<</replace>><</click>> hangs on the wall.</span> <span id="output"></span>
Comments
The #crateText span won't exist until after the Passage has been completely processed to generate it's HTML output, this is why you get the "no elements matched selector" error because it does not yet.
I also noticed that the <<replace "#chest">> macro call in your example is missing a Quotation mark at the end of the element ID.
Try the following:
Thank you in advance for being so patient with a beginner such as myself.
Assuming your $inventory variable contains an Array you may want to use SugarCube's built-in <Array>.includes() method to test for the existence of "Torch", something like the following should do what you want.
Both operators work, I just used not in the example because it is generally less confusing for non-programmers.
So could I also use <<if ! $inventory.includes("Torch")>>?