Modifying Custom Save Title code

Twine Version: 2.3.8
Story Format: SugarCube 2.31.1

Based on HiEV’s Custom Save Title code

Config.saves.onSave = function (save) {
   save.title = prompt("Enter Save Slot Title:", save.title);
};

When I “Save to Disk”, the prompt might confuse the user into thinking they are naming the file, which it doesn’t (since that aspect is done in SC’s save.js). So how should I disable the prompt for that case? And if I have autosave turned on, I would also like to just auto name the save without a prompt. For the latter I have done this:

Config.saves.onSave = function (save) {
	if (tags().includes("bookmark")) {
    	save.title = "chapter " + State.variables.chapter + " bookmark";
	}
	else if (tags().includes("autosave")) {
    	save.title = "autosave";
	}
	else {
    	save.title = prompt("Name this Save or use Default:", save.title);
	}
};

I saw a suggestion to add click eventhandler to the Save to Disk button (or the other save buttons), so do I need to write my own onSave management that distinguishes between the different saves? Thank you for your time.

That’s a use case that I hadn’t considered. I can add a second parameter, or something, to the onSave function call that specifies some metadata about the save—at the very least its type; e.g., 'autosave', 'slot', 'disk'.

I’ve gone ahead and created a new issue for this for anyone who wants to toss their two cents in.

1 Like

Okay. The feature to make this easy has been committed to the repo and will be in the next release of SugarCube.

While the documentation will have details, as a preview, using it might look like the following: (borrowing from the OP’s example)

Config.saves.onSave = function (save, details) {
	switch (details.type) {
	case 'autosave':
		save.title = 'autosave';
		break;
	case 'disk':
	case 'serialize':
		save.title = prompt('Name this save or use default:', save.title);
		break;
	default: /* slots */
		save.title = 'Chapter ' + State.variables.chapter + ' bookmark';
		break;
	}
};
2 Likes

In my mind it might probably end up like this, where I don’t do anything for custom title entry when it’s to disk or serialize:

Config.saves.onSave = function (save, details) {
	switch (details.type) {
		case 'autosave':
		    if (tags().includes("bookmark")) {
    	        save.title = "chapter " + State.variables.chapter + " bookmark";
	        }
            else {
			    save.title = 'autosave';
			}
			break;
		case 'disk':
		case 'serialize':
			break;
		default: /* slots */
			save.title = prompt('Name this save or use default:', save.title);
			break;
	}
};

But thank you for the quick response! I will check the development code and see if I can get some ideas; otherwise I will wait for the new release. :innocent: (will check-off solution when I get it working)