Get the collision msg of a gameobject created trough a factory?

Look at the comment.

function init(self)
	msg.post(".", "acquire_input_focus")
	totalBalls = 0
end

function on_input(self, action_id, action)
	if action_id == hash("leftclick") then
		if action.pressed then
			totalBalls = totalBalls + 1
			factory.create( "#balls", vmath.vector3(action.x, action.y, 0), nil, nil, vmath.vector3(0.5, 0.5, 1) )
			print("Total balls:",totalBalls)
		end
	elseif action_id == hash("rightclick") then
		if action.pressed then
			factory.create( "#collision", vmath.vector3(action.x, action.y, 0) )
            --
			-- I want to remove whatever gameobject this
            -- newly created gameobject touches,
            -- but need to get the collision message for
            -- that. How would I do this?
            --
		end
	end
end

--function on_message(self, message_id, message)
	
--end

I would have the collision object forward the message to this script, and do the deleting at that point.

How would I forward it ?

Just like any other message, using msg.post:

As an example, something like this:

function on_message(self, message_id, message, sender)

	if message_id == hash("collision_message_id_here") then
		msg.post("url_to_main_script", "delete_collision", {message = message, sender = sender})
	end

end

Why are you not having a script on the game object you are creating through the factory?

1 Like

I’ve done it the way you said @britzl. Thanks for the suggestion!

1 Like