Hello! I'm currently making a visual novel and there's this part in the game where I want the browser window to suddenly exit (its horror, you see

). What should I put in the scenes.xmugly to make that happen? Also, once it has been reopened (if closing the browser window is possible), how can I make it go to a new scene, instead of repeating the game from the start? TIA!
Hi adriitakumi!
That's something you cannot do with commands alone. One part of it would involve saving in a global/persistent variable that the player has reached that point in the game. In your first scene you could then check for this variable and go to the next scene accordingly.
In your first scene:
Code:
. localize ~window_closed
. goto scene after_the_scare, ifvar window_closed, +ifvalue
To exit the window you have to add your own JS function. In the index.html file, change the JS code to something like this:
Code:
using("WSE.functions", "WSE.Game").run(function (functions, Game) {
functions.close = function () {
window.close();
};
// ... whatever was written here before ...
});
In your story you can use the function and set the variable like this:
Code:
. global ~window_closed, +value
. fn ~close
(The "+value" is a shortcut for "value yes".)
Please be aware of the following: closing the window will only work if you opened it using JavaScript in the first place. If the user opened the window by clicking on a normal link or entering the URL to the game directly, this will not work. Therefore you'll have to open your game in a new window or tab using some JS.
Hope this helps!
Thank you for the reply jfhs! So, I should open the index.html file using javascript? Is that right? So that I could be able to close the window using javascript? I tried opening it using window.open function but it doesn't seem to work.. It only opens up a blank page.
Code:
<html>
<head></head>
<body>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
window.open("file:///C:/wamp64/www/webstoryengine/index.html");
}
</script>
</body>
</html>
Also, in what part of my first scene should I place the . localize ~window_closed?
Lastly, do I put the
. global ~window_closed, +value and the
. fn ~close in the part of the story where I want the window to close?
Sorry for the many questions. I'm not so knowledgeable in javascript. TIA!
In your window.open call your are using a local file URL, this won't work! You have to use the URL as it appears in your browser when you open your game on your server. In your case given the local file URL above, this probably is on "http://localhost/webstoryengine/index.html" or something similar.
Yes, you set the global variable right before calling your close function with ". fn ~close". Put both in the place where you actually want the window to be closed. And you check for this variable when the game starts, in your first scene. Put the ". localize ~window_closed" and the conditional goto right at the top of your start scene.
Thank you jfhs! It works wonderfully

keep up the great work!