Implementing a pop-up window in twine sugarcube

If you are requesting technical assistance with Twine, please specify:
Twine Version: version 2.3.16
Story Format: SugarCube 2.36.1

Hi, so I'm trying to implement a pop-up window if the requirements are met.
I'm asking the user for input on a couple of things:

What were your observed values from the system?

Number of Samples Observed: <<textbox "$n" "">>
Mean of PREPARATION station processing time (minutes): <<textbox "$x" "">>
Standard Deviation of PREPARATION station processing time (minutes): <<textbox "$s" "">>

I want the game to automatically check whether the requirements are met or not without the user pressing a button or going to another chapter. I like the user to remain in the same chapter to finish other tasks.
Here are the requirements:

20 <= x <= 40
s < 10

Here is my code for the alert message but the if statement isn't working:
<< if 20 <= $x <= 40 and $s < 10>>
<<script>>
Dialog.setup("Alert", " ");
Dialog.wiki("write here");
Dialog.open();
<</script>>

Another thing, I'm trying to include a passage in this alert message but it won't accept my passage, it contains 10 lines.

Julien,

If it’s all the code you have implemented, I can spot some issues here. The good thing is I can offer solutions. Note I will offer a solution inside the same chapter as you expect, but not without clickon a button, it would need some javascprit use I’m not able to write. Basically you’d want to set an alert when the reader click somewehere outside the textbox he has just filled.

First, a passage is read at once, then before the player has any chance to enter any value in any box. At this point $n, $x and $s are blank, then the conditions of the <<if>><</if>> macro cannot be properly tested.

Second an <<if>><</if>> macro https://www.motoslave.net/sugarcube/2/docs/#macros-macro-if has a precise structure. In this case you forgot the closing <</if>>. Also you can’t concatenate two conditions in one. $x between 20 and 40 is really two conditions in Sugarcube mode, so you need one condition $x greater than or equal to 20 and one condtion $x lesser than or equal to 40.

Lastly, you can combine Dialog.wiki() ans Story.get().processText() Story.get() to get a passage inside your alert. I’m not sure how long the passage can be though.

Here’s a tentative code that might work for you.

What were your observed values from the system?

Number of Samples Observed: <<textbox "$n" "">>
Mean of PREPARATION station processing time (minutes): <<textbox "$x" "">>
Standard Deviation of PREPARATION station processing time (minutes): <<textbox "$s" "">>

<<silently>>I want the game to automatically check whether the requirements are met or not without the user pressing a button or going to another chapter. I like the user to remain in the same chapter to finish other tasks.
Here are the requirements:

20 <= x <= 40
s < 10

Here's the code for the alert<</silently>>
<<link "All set">><<replace "#test">>
<<if 20 <= $x && $x <= 40 and $s < 10>>
<<script>>
Dialog.setup("Alert", " ");
Dialog.wiki(Story.get("write here").processText());
Dialog.open();
<</script>><</if>>
<</replace>><</link>><span id="test"></span>

Note at this point you need a passage named ‘write here’ to fill the popup.
Also, it looks you’re trying to create an alert if the requirements are met only, not when they are not, If it’s not your intention you might have to reverse all conditions in your <<if>> macro.

Thanks a lot!! I’ll try this and see if it works.