SugarCube 2.0: Dialog API
Unlike Harlowe, SugarCube comes with a built-in modal display called <a href="http://www.motoslave.net/sugarcube/2/docs/api-dialog.html">//Dialog//</a>. Through calling its //setup()//, //wiki()// / //append()//, and then //open()// functions, a new dialog window can be prepared and opened.
[[Open Dialog]]
<<script>>
Dialog.setup("Look! A dialog window!");
Dialog.wiki("See? It is a dialog window. <h2>And it even handles HTML!</h2>");
Dialog.open();
<</script>>
Like other parts of the SugarCube API, it must be called within {{{<<script>>}}} tags, those that signify not just code, but code using SugarCube functions -- it needs one, {{{<<script>>}}}, to open and another, {{{<</script>>}}}, to close it.
[[Is it open?]]While it may be useful to open a //Dialog// window, knowing when it is open, and then acting on the information, can also be quite helpful. The {{{Dialog.isOpen()}}} function returns a boolean value if the dialog window is open or not.
Along with using the {{{Dialog.append()}}} function, content can be added to the dialog window. (Note: {{{wiki()}}} will act on markup and {{{append()}}} will not.)
<<script>>
Dialog.setup("New title");
Dialog.wiki("Some content");
Dialog.open();
if (Dialog.isOpen()) {
Dialog.append("<br>This adds a line.");
Dialog.wiki("<br>This adds a //wiki markup// line.");
}
<</script>>