nwjs - catching close event on window X button. [SOLVED]

0 favourites
  • 2 posts
From the Asset Store
J-BoB Game Button Sound Pack comes with 300 high-quality sound effects
  • Hello!

    There's a post from 4 years ago (https://www.construct.net/en/forum/construct-2/how-do-i-18/window-close-113911) about being able to run an event before the NWjs window closes when pressing the X(close) button of the actual window. Rojohound gave an example of how this can be done at the bottom of the post, and I was hoping it would still work to this day, seeing as the NWjs documentation is still the same for the solution. However, it has proven futile for me.

    I wanted to put up a confirmation window before the game closes when pressing the x button of the actual window. So I adapted the javascript code given in the post linked above to this:

    "var win=nw.Window.get(); win.on('close', function() {c2_callFunction('nw.js close',[]);});"

    As you can see, I omitted the win.close(true); which is supposed to result in the window being prevented from closing (NWjs documentation example: https://docs.nwjs.io/en/latest/References/Window/#wincloseforce), but alas, doesn't work.

    Maybe construct 2 is executing a window close event sometime later and thus overwriting the browser execute javascript event in the event sheet?

    I've got the latest NWjs version (11th nov. 2020) for construct 2 and the latest version of construct 2 (279). Trying to run this on a Windows 8.1 pro computer.

    Anyone who has any info on this? R0J0hound?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ah, look at that. Had to do with what event sheet I chose to put the code into. I thought I could add it in the included event sheet instead of the event sheet for the actual layout. Doesn't work that way, but putting it in the same layout event sheet works!

    Good for anyone else who might be wondering in the future.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)