How to get url instead of id from factory.create() (SOLVED)

Hi friends
i want to push some objects to a table to pass that table of objects as argument to my module. i use “factory.create()” to create objects i want to pass to my module. it’s my code:

local myTable = {}
local function instantiate()
	for i=1, 6 do
		inst = factory.create("/controller#yellowFactory")
		myTable[i] = inst
	end
end

As i understand factory.create returns hash(“id”) not complete url, so module couldn’t find objects if they are not in same collection. how can i get objects url instead of their hash(ids) to push urls to my table? maybe it’s general question " how to get url from hash(id) but in this case that’s what i need.

local id = factory.create()
local url = msg.url(nil, id, nil)

A url has three parts: socket, path, and fragment (fragment == component). The “path” is the same as an “id”.
You can access each part with those keys, like so: url.socket, url.path, url.fragment. This can be useful to compare things:

if id == url.path then
3 Likes

I recently added a new section in the Factory component docs to cover this: https://defold.com/manuals/factory/#addressing-of-factory-created-objects

4 Likes