You have to do it like this:
<<run Dialog.setup($testname)>> /* setup dialog box */
<<run Dialog.wiki("Hello, world!")>> /* add content to dialog box */
<<run Dialog.open()>> /* display dialog box */
Dialog.setup() doesn’t open a dialog, it only ‘prepares’ it to be opened by Dialog.open().
Unfortunately, you also can’t use Dialog.setup() and Dialog.open() if a dialog is already open. If you’re planning to use dialogs a lot in your story, I’d define a macro to handle all the dialog stuff. Put into your Story Javascript:
function dialog(title = "Default Title", message) {
if (!Dialog.isOpen()) {
Dialog.setup(title);
Dialog.wiki(message);
Dialog.open();
} else {
Dialog.wiki(message);
}
}
Macro.add('dialog', {
tags: null,
handler: function() {
title = this.args[0]
message = this.payload[0].contents
dialog(title, message)
}
});
That defines a custom <<dialog>>
macro you can use like this:
<<dialog "This is a title!">>Hello, world!<</dialog>>
<<dialog>> This text will be added onto the previous dialog!<</dialog>>
<<dialog "Invisible title!">> The title on this macro will be ignored
because the previous dialog is still open!<</dialog>>
<<run Dialog.close()>>
<<dialog "This is another title!">>
This text is displayed in a new dialog with a new title,
because Dialog.close() closed the previous one.
<</dialog>>
Also, you seem confused by whether or not to use quotation marks around variables. It is pretty confusing. Suppose you have code like this:
<<set $defaultName to "John Smith">>
<<set $name to "">>
<<textbox "$name" $defaultName>>
Why doesn’t $defaultName have quotes around it? Because you’re passing the content of the variable to the macro; the above is equivalent to typing <<textbox "$name" "John Smith">>
.
So why does $name have quotes around it? Because without the quotation marks, Sugarcube would read the content of the $name variable, i.e., ""
.
The creator of Sugarcube had to work around this, so they had macros like <<textbox>>
that modify variables directly require you to quote the variable name so the code knows which variable to access. In all other situations, where you want the content of the variable instead, you don’t use the quotation marks.
In this case, you want Dialog.setup($testname1)
(or <<dialog $testname1>>
if you’re using the macro above), since you want the content of the $testname1 variable, not the variable itself.