Why my factory does not appears on the screen?

I tried to do like in side-scroller example, but this code does not work

local frequency = 0.5
local min_y = 60
local max_y = 600
function init(self)
        self.timer = 1/frequency
	math.randomseed(0)
end
function update(self, dt)
	self.timer = self.timer - dt
	if self.timer <= 0 then
		self.timer = 1/frequency
		local pos = go.get_position()
		pos.y = math.random(min_y, max_y)
		local spider = "#orange_factory"
		msg.post(spider, "create", {position = pos})
	end
end

And code from orange_factory/orange.go/orange.script

function init(self)
	self.speed = - 300
	self.score = 1
end	
function update(self, dt)
    local pos = go.get_position()
    pos.x = pos.x + self.speed * dt
    go.set_position(pos)
end
function on_message(self, message_id, message, sender)
end

You should use factory.create(). See http://www.defold.com/ref/factory/#factory.create:url--position---rotation---properties---scale-

1 Like

I tried, but how should I do this? I’m sorry, but I’m new in game development. In side-scroller tutorial I haven’t seen anything about factory.create.

This should be:

factory.create(spider, pos)
1 Like

I’m gonna check that tutorial. It used to be that you sent messages to factories and that might still work.

1 Like

Yes, that tutorial contained some old code. It’s still working but the update() function of “factory.script” should look like this:

function update(self, dt)
	self.timer = self.timer - dt
	if self.timer <= 0 then
		self.timer = 1/frequency
		local p = go.get_position()
		p.y = vmath.lerp(math.random(), min_y, max_y)
		local component = "#star_factory"
		if math.random() < bonus_prob then
			-- component = "#bonus_factory"
		end
		factory.create(component, p)
	end
end