> For the complete documentation index, see [llms.txt](https://developers.newbluefx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.newbluefx.com/api-examples/sample-controllers-tour/03-save-and-load-state.md).

# Save and Load State

Continuing with this simple example, we add another useful capability - saving the state of the controller to the project, and loading it back when the project file is opened.

You may want to save the state of your controller directly in the project so the next time the user opens the project, any state information is reloaded.

To do this:

1. Keep all information that needs to be saved and loaded in one JavaScript object.
2. Whenever something changes in these settings, save it out using the [`saveSettings`](/captivate-api/javascript-api-reference/using-the-servicehandler/additional-methods-with-scheduler.md#savesettings-method) command.
3. On startup, retrieve the input settings using the [`loadSettings`](/captivate-api/javascript-api-reference/using-the-servicehandler/additional-methods-with-scheduler.md#loadsettings-method) command.

In this example, the JavaScript object that manages all of the state information is called “settings.” Saving the state the code looks like this:

```javascript
// Save this latest state in the project.
scheduler.saveSettings(inputName, JSON.stringify(settings));
```

This should be called any time the settings change, typically when the user makes a change in the UI.

To retrieve the settings, call `loadSettings` from the project when the `ServiceHandler` connects:

```javascript
// On startup, retrieve the input settings from the project.
scheduler.loadSettings(inputName, (projectSettings) => {
  // Convert into a JavaScript object.
  let newSettings = JSON.parse(projectSettings);
  // ... apply the settings to the UI
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers.newbluefx.com/api-examples/sample-controllers-tour/03-save-and-load-state.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
