Short background:
Basically I have found defold a few days ago - bonafide newbie here - , I have created a main collection and created a label object, set up input_bindings (Space, h, mouse_left, mouse_right) and it took me an hour to get the label to change content base on the inputs. Started to make a rudimentary text game and all was fine and working 100%, but I run into the issue, that I could not restart my game when it ended >> parsing the defold manual I found out about collection proxies that can be reset (load/unload levels) and it was the perfect solution for my problem.
Following the manual I have created a new collection, a collection proxy, moved all objects and code over to the new collection from main, set up proxy loading, message passing and after a while I managed to load the same stuff, but now via a proxy. Hurray!
And now I can not make the input messages pass between the main and the proxy.
After reading trough this forum I have found and added the debug code that solved someones misnamed proxy/game object Id problem, but I found that I have no such misnaming in my code.
Based on the defold manual and the defold teams video âThe basics of addressing and message passingâ all the code seems to be correct.
Can you help me what am I missing/doing wrong - why does the code not work?
Win10_x64 - HTML5 project
I have uploaded the project to git:
I guess some of your problems come from refactoring the code. Right now main.script is trying to capture the input in the on_message function, while it has to do that in the on_input function, like so:
function on_input(self, action_id, action)
if action_id == hash("spacebar") then
msg.post("TitleScreen:/go#TitleScreen", "spacebar")
end
end
Then, after youâve passed it to the other collection, you have to use the on_message function in TitleScreen.script to receive it. That function is already there, but youâre trying to compare action_id in it, while you have to use message_id instead.
An alternative solution is to just listen to the input directly in TitleScreen.script without having to send a message from main.script. In that case, just remember to add
msg.post(".", "acquire_input_focus")
to your init function in TitleScreen.script first.
I have updated the code - also on github - based on your first suggestion, and itâs kinda working, but not fully.
Let me explain:
The message is passed, but the action component is not passed and I had to remove those lines from the code. So now I have a key press information, but can not differentiate between a pressed or released action.
On your second suggestion as to moving the input focus to the proxy script, in the âCaveats and Common issuesâ section of the defold manual (Collection proxy manual) there is a section on Inputs stating:
âIf you have objects in your loaded collection that require input actions, you need to make sure that the game object that contains the collection proxy acquires input. When the game object receives input messages these are propagated to the components of that object, i.e. the collection proxies. The input actions are sent via the proxy into the loaded collection.â
This is what I have experimented with before I even resorted to the - kinda manual - message passing, but it would not work. This above defold manual text implies add - msg.post(".", âacquire_input_focusâ) - and it just worksâ˘, but alas, nopeâŚ
I have tried all variations of in which script I put the - msg.post(".", âacquire_input_focusâ) - and both on_input/on_message functions to try to capture the inputs, but based on the above the acquire clearly should go to the main.collection and logically in the proxy the on_input function should be used, still the propagation did not happen.
I went with option two, and did the double acquire and use on_input in proxy method.
Thank you so much! I have spent hours on this and felt a bit of a let down that I could not figure it out, but now I am reinvigorated, so after a good 12 hours of much needed sleep, I will hop back on the defold train.
Updated the code on github.
Thanks again!
P.S.: Next project >> figure out how to mark this topic SOLVEDâŚ