How to child a factory created game object?

I want another game object to act almost like an extension of the original. I believe childing could work for this. How would I child the newly created object. I think i can child an object but I cant seem to find how to get the id. I tried to follow the “guide” on this forum( Msg.post to an object created by a factory ) but cant seem to find out how to.

The game object ID is the value returned by the function factory.create(…). Just as in the example that you posted, the following code by @sven does the trick.

local new_go = factory.create(...)
msg.post(new_go, "hello_from_the_other_side")

‘new_go’ will in this example be the ID of the newly created game object.

3 Likes

Ok, I managed to child but the game object still does not act as an extension of the parent. Use a as the parent. - as the child and e as a wall. If I where to move down in a situation like that the parent moves down but the child stays, meaning the game objects are not where I want them, I want the parent to stay as well because I want the child to act as a extension of the parent. Is there anyway for that to happen whilst still having separate game objects?
|
v
a -
a e

I would suggest looking at this parent/child documentation, and make sure that everything in the example is set up properly in your project.

If that does not work, could you provide your code? It is hard to say what goes wrong without it.

2 Likes

Yes, this. Super hard to tell what is wrong without also looking at some code.

2 Likes
function init(self)
	tim = 3
end

function on_message(self, message_id, message, sender)
	if message_id == hash("tim") then
		tim = 3
	end
end

function on_input(self, action_id, dt)
	if action_id == hash("STAB!") and 
	tim == 3 then
		local new_go = factory.create("#factory")
		msg.post(new_go, "set_parent", { parent_id = go.get_id("logo") })
		tim = 2
	end
end

heres the code for the creator

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


function on_input(self, action_id, action)
	if action_id == hash("back") then
		go.delete()
		msg.post("logo#stabb", "tim")
	end
end

heres the code for the created
" stabb" is the name of the first code

1 Like