0 votes
by (470 points)

Hello, I want to delete all saves after restart. I hid "Saves" and "Restart" on UI bar and created my own button Restart (I save game after each action of player). In GameOver restart without popup dialog is what I need, so I use Engine.restart(). But for button "Restart" I need question with "Ok" and "Close". If "Ok" I want restart and clear saves. But UI.restart(Save.clear()) doesn't work. 

::StoryMenu
<<link "RESTART">><<script>>UI.restart(Save.clear());<</script>><</link>>

::GameOver
Game Over
<<script>>Save.clear()<</script>>
<<link "Start again">><<script>>Engine.restart();<</script>><</link>>

 

2 Answers

+1 vote
by (68.6k points)
edited by
 
Best answer

As noted by greyelf in their answer, deleting a player's saves is generally not something you want to do without their consent.  In your specific case, I suppose it works out.

Try something like the following: (EDIT: updated the code to work anywhere)

<<script>>
Dialog.addClickHandler(
	jQuery('<a id="game-restart">Restart</a>').appendTo(output),
	null,
	function () {
		jQuery(Dialog.setup(L10n.get('restartTitle'), 'restart'))
			.append(
				  '<p>' + L10n.get('restartPrompt') + '</p><ul class="buttons">'
				+ '<li><button id="restart-ok">' + L10n.get(['restartOk', 'ok']) + '</button></li>'
				+ '<li><button id="restart-cancel" class="ui-close">' + L10n.get(['restartCancel', 'cancel']) + '</button></li>'
				+ '</ul>'
			)
			.find('#restart-ok')
				.ariaClick({ one : true }, function () {
					jQuery(document).one(':dialogclose', function () {
						Save.clear();
						Engine.restart();
					});
					Dialog.close();
				});
	}
);
<</script>>

 

by (470 points)
Thank you very much. I would never invent something like this without your help. But it doesn't work, and I cannot repair cause don't understand how it works. I copy/pasted it in StoryMenu.
by (68.6k points)
Ah, sorry.  I missed that you were placing it within the StoryMenu special passage.  The original code does work in normal passages.  I've updated the answer with code which should work everywhere.
+1 vote
by (159k points)

Opinion: I don't believe that deleting all of a Player's saves is a good idea, especially without asking them if they are OK with you doing that.

As documented the options object parameter of the UI.restart() function only accepts two predefined key/value pairs, and neither of them is a on-close function call like you are trying to passage in your example.

Based on your use-case I believe you will need to define your own dialog as explained in the Dialog.addClickHandler() function documentation.

by (470 points)

It's roguelike type game with many replays. Player cannot save game, only start or continue. Game is saved after each action of player. Thus if game over it means that progress must be deleted. But if player wants to restart in the mid of game I need to ask him if he sure. I read about Dialog.addClickHandler() but cannot understand how use it.(
 

<<link "Restart">><<script>>
    Dialog.addClickHandler("#ui-dialog", null, function () {
        Dialog.setup("Restart", "my-dialog-class");
    },
    function () {Save.clear(); Engine.restart();}
    );
<</script>><</link>>


 

by (68.6k points)
You cannot use the Dialog.addClickHandler() method with the <<link>> macro, you'd use it in lieu of <<link>> instead.  See my answer for details.
...