Well, I don’t think it worked for me without acquiring input focus in screen.script which is a component of all the game objects (corresponding to each screen in the game) in main.collection.
Did it work on the project I sent you?
Is final() supposed to get called when Monarch switches between screens? With whatever I’m doing, I’m able to detect input in game.collection when it’s open and also from another collection I have called end.collection after I open it with Monarch. Is this how Monarch is supposed to works?
final() is called on a script component when the game object the script is attached to is removed. The whole process of input is supposed to work like this:
The above screenshot is of the bootstrap collection of the example that comes with Monarch. The main.script does:
monarch.show(hash("menu"))
When this happens Monarch will start the process of showing the menu screen. The first thing that happens is that Monarch will acquire input focus for the menu game object and then it will load the menu.collection containing the screen itself. Acquiring input focus for the game object containing the collection proxy is handled by Monarch and it is something that must happen if you want any input from the user to propagate to any scripts within the menu.collection. This is described in the section on Input and Collection Proxies in the Defold manual on input. Note that you still have to acquire_input_focus in any script inside the menu.collection yourself.
What this means is that Monarch will make sure that input can propagate down to any script attached to a game object in the topmost screen of the Monarch input stack. Monarch will acquire input focus for the topmost screen and automatically release input focus from any other screen. BUT you still have to take care of acquiring input focus within the screen itself.
I’m really feel like I’m doing exactly what you’re saying, but now it doesn’t seem to be working. The only place where I am acquiring input focus is in game.gui_script where I get input from my 2 virtual joysticks. (They are GUI nodes) What you’re saying makes sense to me, but it just isn’t working. It only works when I add message passes to acquire input in Monarch’s screen.script and game.script which is attached to a go called game.go in game.collection.
I did send you my project by email. If you get a chance, I would really appreciate it if you could try to get it to work. I’m really, really confused.
Ok, so here’s what’s going on. When a screen is shown a series of things happen:
The screen is unloaded if the reload flag is set
The screen is loaded if it’s not already loaded
The screen transition is played (instantly shown if no TransitionUrl is provided)
Input is acquired
A focus gained message is posted to the screen if a FocusUrl is provided
DONE!
This sequence can be seen here:
The steps described above all happen in sequence, one after the other. If one step fails the next will not happen. In your case you specify a Transition Url for your game screen (game:/game#game) but in the game.script you do not handle the transition message and send a monarch.TRANSITION.DONE when the game screen transition is completed. And since you don’t send a monarch.TRANSITION.DONE message the next step in the sequence will not happen (which is acquiring of input).
The solution is to either handle the screen transition or remove the Transition Url.
It may seem like a stupid thing to wait for the screen transition to complete but I think in certain cases it makes sense to actually wait to acquire input until the transition is finished. And it’s better to have it that way and if you don’t want to wait for the transition to finish you can handle that yourself in your transition code by sending monarch.TRANSITION.DONE while the transition is running.
Make a short video explaining it with a simple flash animation. For some reason I get the urge to do tutorials on Defold(Basics) but then I get lazy and rather sleep