I’m setting my camera’s position through msg.post. In the same way I want to use the messaging api to retrieve the current position but as it seems it’s not working. Does msg.post redirect return values from on_message?
local pos = msg.post("camera#cameraController", "get_camera_position")
camera#cameraController
function on_message(self, message_id, message, sender)
-- Add message-handling code here
-- Camera view and projection arrives here. Store them.
No it does not send back values by itself, you have to handle that yourself.
If you want to do with message functions you will have to send one back
function init(self)
msg.post("camera#cameraController", "get_camera_position")
self.camera_position = 0
end
function on_message(self, message_id, message, sender)
if message_id == hash("get_camera_position") then
self.camera_position = message.camera_position
end
end
camera#cameraController
function on_message(self, message_id, message, sender)
-- Add message-handling code here
-- Camera view and projection arrives here. Store them.
if message_id == hash("set_camera_position") then
go.set_position(message.pos)
end
if message_id == hash("get_camera_position") then
msg.post(sender, message_id, {camera_position = go.get_position("camera_object")})
end
end
I’ll use go.get_position("camera#cameraController"), it fits my needs There was no particular reason why I wanted to use the message api, I’m just new to Defold and wasn’t aware of that. Thanks!