If (! tag().includes … isn’t working for me

In an attempt to create a method that would prevent the infamous << return >> macro loop, to avoid soft locking myself when trying to access my inventory and the other passages it needs in order for my stuff to work, i went to google, and long story short I pasted this JavaScript into the story stylesheet!

predisplay["Menu Return"] = function (Menu Check) {
if (! tags().contains('noreturn')){State.variables.return = passage();
}
};

What I’m trying to do is make the script save what passage I’m on into a $ variable that i can put into a passage link! However, I don’t want it save any passaged that are marked with a tag named “noreturn”!

The problem is that it doesn’t work! the words “if”,“.contains”, and “State.variables.return” are all highlighted in dark red and I’ve never used JavaScript before! The debug menu when i play doesn’t show any $ variable for return, and it just sends me to a passage literally named “$return” instead of anything else!

I’ve also tried

predisplay["Menu Return"] = function (Menu Check) {
if (! tags().includes('noreturn')){State.variables.return = passage();
}
};

Same results there
I’m using twine 2.10.0, sugarcube 2.37.0

That might be your issue. The stylesheet is for CSS, not Javascript. Javascript need to go in the Javascript section.

You might also want to look at the arbitrarily long return from the documentation, which does what you’re trying to do.

2 Likes

Thanks so much! It didnt quite work when i moved it to javascript though, however i found that i didnt need it and could instead put

<<if not tags().includes("noreturn")>>
	<<set $return to passage()>>
<</if>>

in my story caption passage!

1 Like