Howdy, Stranger!

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

Using a passage name as an if statement

I found some code that will allow you to check a passage's tags and then if the statement is true, to set the current passage name as a variable.
But the code is obviously for a different version of twine. Maybe Harlowe? And I'm using sugarcane.

What I want is a code snippet that says

If passage tags do not contain blah blah
set variable to passage name.

I cannot find an example for sugarcane and my fumbling is not working.
Please help!


  • The equivalent for Sugarcane is the tags() function, which can be found in the Twine 1 Reference.

    In your use-case because you want to check that a tag is not included you want to check that the return is equal to -1. (eg. == -1)
  • It still doesn't seem to be working.
    What I'm using is header tagged passage that says
    <<if tags().indexOf("party") is -1>>
    <<set $last to passage()>>

    Then I have a link like this: $last

    But the link doesn't work.
  • A header-tagged passage has no special meaning to Sugarcane.
  • oh poop. No wonder.
  • Is there another way to get every page to run that code at the beginning? Can I put it in the CSS?
  • You can use Javascript like the following to do what you want, the code goes within your story's script tagged passage. If your story does not already have one of these special passages you can use the Story > New > Script menu items to create one.
    prerender["track passage name"] = function(elem){
    	if (tags().indexOf("party") == -1){
    		state.history[0].variables["last"] = passage();
  • Thank you. You fixed two of my problems today.
Sign In or Register to comment.