Changing difficulty setting with dropdown list

Hi. I’m trying to create a dropdown menu on the Settings page in order to change my story’s difficulty. This is what I have in my Javascript section:

// Define variable using default value
State.variables.settings = {
    Difficulty: "Normal" 
};

// Create dropdown
Setting.addList("Difficulty", {
    label: "Choose a difficulty level.",
    list: ["Easy", "Normal", "Hard"],
    default: "Normal",
    onChange: function(value) {
    State.variables.settings.Difficulty = value;
    }
});

I can access the initial value using <<print State.variables.settings.Difficulty>>.

However, once I’ve made a change to the variable using the dropdown list it always returns ‘undefined’.

I’m new to Javascript - am I missing something obvious?

Thanks.

You can access setting variables in your regular SugarCube code as:

settings.difficulty
<<print settings.difficulty>>
<<if settings.difficulty is "Easy">>

(also the example in the Documentation is the best for this kind of setting!)

Setting.addList("difficulty", {
	label   : "Choose a difficulty level.",
	list    : ["Easy", "Normal", "Hard", "INSANE"],
	default : "Normal"
});

Got it working. Thanks!