Managing URL sockets

I’m using collection proxies to load new levels (through Monarch), so each level has its own socket. The problem is that I have socket-dependant code in my collection:

local col = collectionfactory.create("#bulletfactory", go.get_position() + offset)
local url = msg.url("main", col["/root"], "bullet")
go.set(url, "direction", vmath.vector3(self.facing, 0, 0))

This will break in any level that doesn’t have name “main”.

Is there a better way to handle this URL? Or should I store the socket name somewhere?

Can’t you pass the direction value in the properties table when you call collectionfactory.create()

3 Likes

@britzl’s suggestion is best but in case a similar problem pops up, you can pass nil and Defold will use whatever the current socket is:

local url = msg.url(nil, col["/root"], "bullet")
2 Likes