What is difference between
msg.post('.', "acquire_input_focus")
msg.post('#', "acquire_input_focus")
msg.post(nil, "acquire_input_focus")
?
What is difference between
msg.post('.', "acquire_input_focus")
msg.post('#', "acquire_input_focus")
msg.post(nil, "acquire_input_focus")
?
msg.post('.', "acquire_input_focus")
Sends message to self - as in the parent object. You can send a message to anything to tell it to acquire input focus (I’m pretty sure). If a parent object has input focus all components will get sent input down the hierarchy until it’s been consumed.
The other two probably would do nothing. # is for sending a message to a component, and # by itself is used in a shorthand way to send a message to the named component of the parent object, but without anything following it no component is specified. Same with last, no address means nowhere to send. If you specified a named component that is a script with a # it should have the same effect with the parent object getting input focus but I’m not sure. Test? Still, first way is the way you want to be doing it.
to test it I’ve just written the code…
function init(self)
print(msg.url(nil))
print(msg.url('.'))
print(msg.url('#'))
end
got…
DEBUG:SCRIPT: url: [main:/object#script]
DEBUG:SCRIPT: url: [main:/object]
DEBUG:SCRIPT: url: [main:/object#script]
so… are nil and ‘#’ equal?
They may both default to the same default value (reference to actual self?) if a correct path isn’t specified. Not sure.
Yes, it’s all about convenience and how we resolve things. It’s designed similarly to how a file system works. In a terminal you can issue the command ‘cd’ without any parameters, and that will take you to the home directory. Not because no parameter intuitively means your home directory, but because it’s convenient.
Yes. “.” is the current game object. “#”, the current component (script). See http://www.defold.com/manuals/message-passing/ and the “Shorthands” section.
I seem to recall that you discussed deprecating “nil” but I may be wrong, @Ragnar_Svensson
Do you mean that msg.url() without any arguments will throw an error? That will likely break a whole lot of games that depend on msg.url() to get the url of the currently running script.
It will remain as is. We discussed whether it was a good idea or not, based on how lua treats some errors by defaulting to nil, which leads to unintended results. But it’s a part of the API now and won’t change.
I’ve seen it in the controls.gui_script of the Defold examples-project.zip
function on_message(self, message_id, message, sender)
if message_id == hash("aquire_controls") then
self.controls_receiver = sender
elseif message_id == hash("on") then
msg.post(nil, "acquire_input_focus")
elseif message_id == hash("off") then
msg.post(nil, "release_input_focus")
Ok, we should change that. “.” or “#” are clearer.