Help with permanent settings options

Hey! This is my first time making a forum, so I’m sorry if it’s weird or hard to understand.

I have a string in my game at the very first passage that says:

<>

When I playtest my game starting from this passage, on the UI bar, the options menu shows and the stuff inside the options tab appear. But when I try to open the game on a different passage, the options disappear, and I’m assuming that is because the options only show on this passage, and I have to somehow put it in the CSS.

The thing is though, when I tried to put this exact same string into the CSS, I get errors on

“Content Settings”, “You must refresh your page to see changes.”

“allowAdultContent”

label: “Allow Adult Content:”

Does anyone know why? And could anyone help me put it as a CSS?

1 Like

Your code isn’t showing on the forum, but try putting whatever code you have in the Start passage in the StoryInit passage instead.

Both passages have to be titled exactly that.

(Code in the StoryInit passage is executed no matter which passage the game starts from. Code in the Start passage is only executed when you visit that passage.)

I tried to copy and paste my code into a passage called “StoryInit” but when I playtest it, I get a notification saying that there isn’t a closing statement for “script”, even though at the end of the string I have “/script” already.

If you can, please post all of the code that you’re inserting into StoryInit. There are many possible causes for the error message that you’ve reported, although an overlooked typo is common.

To ensure that readers of the post can see the code, type three back-ticks ``` on the preceding and subsequent lines. On most U.S. keyboards, the “back-tick” character (`) is in the upper-left corner of the keyboard, on the same key as the tilde (~), but not shifted. The code you post will then look something like this:

```
<<script>>
  /* javascript stuff here; */
<</script>

<<set $InitVariable=5.0>>
```

Note my typo in the example above :wink:

Based on the fact that you mentioned “settings” and “label:” in your question, I will assume that you are trying to use the Setting API.

note: All the API related sections of the documentation cover how to use JavaScript code to preform specific actions.

As the majority of the functions in the Settings API are used to define “settings” during the start-up process of your project, such code should be placed within the Story JavaScript area of your project. This area can be found by selecting the Story then JavaScript menu items in the Twine 2.x application’s Passage Map toolbar.

I’m not exactly sure how to send it. I sent the full code on the original post, but it was all cut off.

Yep. Specifically, I want to have a settings that would enable adult content if players are comfortable playing with themes of violence, drugs, and sex, so by default they wouldn’t be able to play through that unless they turned that on. But I noticed on different passages or when I loaded a save, the settings UI disappeared.

The toolbar above this forum’s comment field has a </> button in it, that can be used to wrap a code example in Preformatted Text markup.

So to include a code example in your comment:

  1. Place the typing cursor at the start of an empty line.
  2. Select the </> button, which will add the following to the comment field.
    ```
    type or paste code here
    ```
  3. Add your code example between the two lines that start with ```
    ```
    <<set $thing to “value”>>
    <<if $thing is “value”>>…do something…<>
    ```

The result of point 3 should look something like the following to anyone reading your posted comment.

<<set $thing to "value">>
<<if $thing is "value">>..do something..<</if>>

The “Basic toggle setting” example in the Setting.addToggle() function documentation demonstrates the functionality you want. Using your original question as a guild, adding code like the following to the Story JavaScript area of your project should produce the correct outcomes in the Settings dialog…

Setting.addHeader("Content Settings", "You must refresh your page to see changes.");
Setting.addToggle("allowAdultContent", {
	label : "Allow Adult Content:"
});

…and you will then be able to use the associate settings.allowAdultContent Boolean variable to conditionally show the content of a Passage.

Welcome to the Library!
Which book do you want to read?
[[Adventure Book|Read an Adventure]]
[[History Book|Learn Some History]]
<<if settings.allowAdultContent>>[[Erotic Novel|Waste some time]]<</if>>

(Deleted last two posts because I found where it was)

<<script>>
	Setting.addHeader("Content Settings", "You must refresh your page to see changes.");
	Setting.addToggle("allowAdultContent", {
		label: "Allow Adult Content?"
	    default: false
});
<</script>>

And I would put this in the Story JavaScript area instead of the StoryInit?

Yes.
Because it is JavaScript code.

I got a different error.

[tw-user-script-0]: Invalid or unexpected token.

I think a comma is missing, end of the third line (and I would have one end of the fourth too, though it is optional).

	Setting.addHeader("Content Settings", "You must refresh your page to see changes.");
	Setting.addToggle("allowAdultContent", {
		label: "Allow Adult Content?",
	    default: false,
});

You need a coma at the end of the label: "Allow Adult Content?" line.

I put the comma there now, and it still gives me the same error.

Setting.addHeader("Content Settings", “You must refresh your page to see changes.”);
Setting.addToggle("allowAdultContent", {
    label : "Allow Adult Content?",
 	default : false, 
});

On Story JavaScript, the only things in red are

  • “Content Settings”
  • “allowAdultContent”
  • “Allow Adult Content?”

There are smart quotes instead of straight quotes around “You must refresh your page to see changes”. Try pasting this:

Setting.addHeader("Content Settings", "You must refresh your page to see changes.");
Setting.addToggle("allowAdultContent", {
    label : "Allow Adult Content?",
 	default : false, 
});

Thanks! Everything works just fine now. Thank you everyone for the help.