0 votes
by (350 points)
Hi.  I've been using the Sugarcube dialog-api for simple look-at links (rather than switching passage completely).  Now I'm interested in using it for simple interactions (a short conversation, for instance).  I'm wondering if there's a best way to force the user to make a choice in the dialog, ie. to prevent them from closing it by clicking away.

I've searched the Sugarcube2 docs, forums and QA, but no luck.

Thanks for any help you can provide.

1 Answer

0 votes
by (350 points)
edited by
Best answer

I've worked out an answer.  For anyone else wishing to prevent a dialog from being dismissable through clicking outside of it, here's what I did.

The main thing to focus on is the 'if/else' block in the first (JavaScript) code section.  It toggles the user's ability to dismiss the popup by clicking outside of it.


JavaScript code:

Macro.add("popLink", { tags : null, handler: function()
	var a = $("<a/>");
	a.data("title", this.args[1]);
	a.data("content", this.payload[0].contents);
	a.data("undismissable", this.args[2]);
	Dialog.addClickHandler(a, null, onPopLinkClicked);
function onPopLinkClicked(evt)
	var $target = $(evt.target);
	if ($target.data("undismissable"))


Passage code:

<<popLink "Click me for normal dialog" "My title" false>><a onclick='SugarCube.Dialog.close();'>Close</a><</popLink>>
<<popLink "Click me for undismissable dialog" "My title" true>><a onclick='SugarCube.Dialog.close();'>Close</a><</popLink>>


by (63.1k points)
Looks solid, but you really shouldn't add macros in passage scripts, that's a job for the story JavaScript.
by (350 points)
edited by
Thanks.  The example is not actually representative of my story code (which defines all macros in the story's javascript).  I wrote it specifically for the readability of this answer... but in the interest of promoting best practice, I'll adjust the answer.