How do I On window close (x)

Get help using Construct 2

Post » Sat Jun 11, 2016 10:56 pm

How do I fire event when X is clicked to close window?
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Sat Jun 11, 2016 11:01 pm

keyboard On key X pressed --> Browser Close

you mean to close the window, or maybe you meant fire an event after the window is closed?
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Sat Jun 11, 2016 11:30 pm

When I click the X in the upper right of nw.js window, fire an event before closing. I can't find any way to do this.
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Sat Jun 11, 2016 11:42 pm

Perhaps by creating a state triggered by pressing X condition. Once triggered, event is executed, once this event is executed, close window
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Sat Jun 11, 2016 11:44 pm

You don't understand Fraktal.

@Ashley , there is no current way to check if window is closing in nw.js
I want to save data to file before user clicks X to close window, but can't because the nw.js object has no condition for this.
We need a condition to check if window is closing.

This is important so that user doesn't lose their progress if they close out. At the moment if I X out of program, nothing can be saved. So a condition that checks is needed.
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Sun Jun 12, 2016 1:25 am

Here's a reference on how to do it with JavaScript:
https://github.com/nwjs/nw.js/wiki/window

My next question that I'll have investigate later is if you can access nw.js with JavaScript with the browser plugin.
If that's possible we can execute a few lines of js at the start of the game that will call a c2 function when the window closes.

Edit:
I'll assume for a moment that you can access nw.js with the browser object.
You'll need the function and browser objects, then execute this js at the start of the layout:

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

Then add this event anywhere. I should be called before the window is closed.
On function "nw.js close"
--- do something

If the js causes an error so it doesn't work I'll have to look into it further when I get a chance.
B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Sun Jun 12, 2016 5:03 pm

thanks, i'll try that out!
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Sun Jun 12, 2016 7:37 pm

@Prominent
Here's the working script for the latest nw.js:

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

I had forgot to make it actually close after the trigger. You can change 'nw.js close' to any function name you want to use.
B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250


Return to How do I....?

Who is online

Users browsing this forum: jaytrott86, Yahoo [Bot] and 6 guests