Modal (pop up window) issue

I’m trying to make an inventory tab but when putting in any code like this:

<<link "Open dialog!">>
  <<script>>
    Dialog.setup("Dialog");
    Dialog.wiki("Hat/Helmet:
You are currently wearing <<linkreplace "Nothing">><<set $Hat to "Nothing">>Nothing<</linkreplace>>|<<if $Snapback is true>><<linkreplace "Snapback">><<set $Hat to "Snapback">>Snapback<</linkreplace>><<else>><</if>>|

Shirt:
You are currently wearing <<linkreplace "Nothing">><<set $Shirt to "Nothing">>Nothing<</linkreplace>>|<<if $Whiteshirt is true>><<linkreplace "White shirt">><<set $Shirt to "White shirt">>a white shirt<</linkreplace>><<else>><</if>>|

Pants:
You are currently wearing <<linkreplace "Nothing">><<set $Pants to "Nothing">>Nothing<</linkreplace>>|<<if $rippedjeans is true>><<linkreplace "Ripped jeans">><<set $Pants to "Ripped jeans">>Ripped jeans<</linkreplace>><<else>><</if>>|");
    Dialog.open();
  <</script>>
<</link>>

I keep getting an

 "Error:<script>: bad evaluation: invalid or unexpected token" 

error message. Can anyone explain what im doing wrong and how to fix it…in…simple terms…

You can’t use sugarcube macros inside a <<script>> tag, it expects everything inside the tag to be pure javascript.

You might like this dialog macro set which allows you to use the dialog API as macros without having to mess with <<script>>/javascript at all.

1 Like

Thank u!!

NOTE: the Dialog.wiki() function has no issues executing Macros!

There are two issues with your code example:

1: The String value being passed to the Dialog.wiki() function has Passage content line-breaks in it.

The String data-type uses a \n escaped character to represent a line-break, and line-breaks in Passage content are represented a different way, which is not supported by the String data-type. And this incompatibility is causing your token error.

2: You are using double quotes to represent two different things in the String value being passed to the Dialog.wiki() function.

You are using a double quote as the delimiters of the String value being passed to the function.
eg.

Dialog.wiki("the String you want the wikifier to process");

…and as the delimiters of the String values you are passing to the Macros contained within the argument being passed to the Dialog.wiki() function…
eg.

<<linkreplace "Nothing">>

…and because of this your existing Dialog.wiki() function call is being broken apart like so when processed…

Dialog.wiki(			/* function start */
"Hat/Helmet: \n You are currently wearing <<linkreplace "	/* String */
Nothing				    /* unknown */
">><<set $Hat to "		/* String */
Nothing				    /* unknown */

... and so forth...

">>Ripped jeans<</linkreplace>><<else>><</if>>|"	/* String */
);						/* function end */

…and the simple way to fix this issue is to alternate the use of both single and double quotes…
eg.

Dialog.wiki('textual content <<macro "string argument">> textual content');

And the simplest way to fix both of the above problems is to place the content you want to display in the dialog within a Passage, and then use an <<include>> macro within the function call to display the contents of that Passage.
eg. (Twee Notation based example)

:: The Passage containing the Link
<<link "Open dialog!">>
    <<script>>
        Dialog.setup("Dialog");
        Dialog.wiki('<<include "Contents of Dialog">>');
        Dialog.open();
    <</script>>
<</link>>

::  Contents of Dialog
Hat/Helmet:
You are currently wearing <<linkreplace "Nothing">><<set $Hat to "Nothing">>Nothing<</linkreplace>>|<<if $Snapback is true>><<linkreplace "Snapback">><<set $Hat to "Snapback">>Snapback<</linkreplace>><<else>><</if>>|

Shirt:
You are currently wearing <<linkreplace "Nothing">><<set $Shirt to "Nothing">>Nothing<</linkreplace>>|<<if $Whiteshirt is true>><<linkreplace "White shirt">><<set $Shirt to "White shirt">>a white shirt<</linkreplace>><<else>><</if>>|

Pants:
You are currently wearing <<linkreplace "Nothing">><<set $Pants to "Nothing">>Nothing<</linkreplace>>|<<if $rippedjeans is true>><<linkreplace "Ripped jeans">><<set $Pants to "Ripped jeans">>Ripped jeans<</linkreplace>><<else>><</if>>|