Message properties not being sent

In my receiving script, I have this code:

-- sine_movement.script
function on_message(self, message_id, message, sender)
	if message_id == hash("disable") then
		self.disabled = true
	elseif message_id == hash("enable") then
		pprint(message)
		self.anchor_pos = message.anchor_pos or vmath.vector3()
		self.disabled = false
	end
end

I send a message like this from another script on the same object:

msg.post("#sine_movement", "enable", { anchor_pos = go.get_position() })

The pprint in the first code block prints out an empty table. So the message is definitely being sent, but the property is not being sent with it. What am I doing wrong here?

It is probably because enable/disable are message_id’s reserved by the engine. I would try using different message_id’s. If you actually want the script to be enabled/disabled as well, I would send that as a result of the new message_id. E.g:

-- sine_movement.script
function on_message(self, message_id, message, sender)
	if message_id == hash("disable_sine_movement") then
		self.disabled = true
		msg.post("#", "disable")
	elseif message_id == hash("enable_sine_movement") then
		pprint(message)
		self.anchor_pos = message.anchor_pos or vmath.vector3()
		self.disabled = false
		msg.post("#", "enable")
	end
end
2 Likes

Yeah, that was the problem, I just changed it to an ID that wasn’t used by game objects already. I can’t easily steal enable and disable for scripts then. :frowning: