Incoming call and window listener (#4831)

Hi!

I would like to activate the pause when there is an incoming call (on mobile). Is this possible somehow? Or, perhaps is the game “minimized” by an incoming call and I have to listen to this event?

Many many thanks!

Yes, I think you will get a window.WINDOW_EVENT_FOCUS_LOST when this happens.

1 Like

Thanks! I will try it!

It works (on my mac)!

But I don’t understand how to remove the callback. I have window.set_listener(window_callback) in a script attached to a collection. In the final function of the script I have tried

window.set_listener(function() end)

but I get the error:

Could not run Window callback because the instance has been deleted.

when I minimize the window after the deletion of the collection containing the script.

So I have to use window.set_listener in a script that is always active?

My apologize if there is something basic I am missing here…

You should probably keep such a script in your main bootstrap collection that is always loaded and then use it to broadcast messages to the parts of your game which would care.

2 Likes

Yes! Thank you, this is what I was thinking… The point is that I need to listen to those events only in the “play phase”. I will do as you suggested.

If you use https://github.com/britzl/ludobits/blob/master/ludobits/m/broadcast.lua then you can register / unregister as needed. I like this pattern in general for these kinds of general communication needs.

2 Likes

Indeed! I was not aware of it and I have coded something very similar on my own. I was already using it for window resize, so now I will manage also focus_lost.

Thank you so much for your advice! Your help is always great!

2 Likes

Can’t you send null as listener function?

No, it seems that you cannot. It complains that it wants a function and not nil.

1 Like

Added issue: Make it possible to unset the window listener by passing nil to window.set_listener() · Issue #4831 · defold/defold · GitHub

This is an excellent first issue for someone wanting to make a contribution!

2 Likes