<<if tags().previous != "inv">>
<<set $room.last = previous()>>
<<endif>>
The above code is supposed to set room.last to previous unless previous has a tag inv. It instead sets any room. Even if it does have that tag. What am I doing wrong?
You need to state which Story Format (name and version) you are using when you ask a question, as answers can be different for each one. I am going to assume you are using SugarCube 1.x
I am also assuming your $room variable is defined something like:
<<set $room to {last: ""}>>
Try using the following:
<<if ! tags(previous()).contains("inv")>>
<<set $room.last to previous()>>
<<endif>>
Virtually everything, within the conditional anyway. It should be something like the following:
<<if not tags(previous()).contains("inv")>>
<<set $room.last to previous()>>
<</if>>
Alternatively, and assuming that this is to allow you to return to the last passage not tagged with inv—for a nested/multi-passage inventory or something to that effect—an equivalent method would be to set $room.last to passage() unless the current passage's tags contains inv. For example:
<<if not tags().contains("inv")>>
<<set $room.last to passage()>>
<</if>>
Comments
I am also assuming your $room variable is defined something like: Try using the following:
Alternatively, and assuming that this is to allow you to return to the last passage not tagged with inv—for a nested/multi-passage inventory or something to that effect—an equivalent method would be to set $room.last to passage() unless the current passage's tags contains inv. For example: