How to create a game object every few seconds[Solved]

Im confused as to how I should approach creating a game object every few seconds. I am using the following code

function init(self)
	self.timer = 2
end

function update(self, dt)
	self.timer = self.timer - dt
	if self.timer < 0 then
		factory.create("#factory")
		self.timer = 2
	end
end

Im also confused as too how I should add a sprite to it. I looked through the Manual and the carrot example. Any help is appreciated. Thanks.

It looks like this would work, noting that dt is the length of time taken since the last frame. Inside your object with this script, you’d need the factory that you are referencing with this line:

factory.create("#factory")

Within that factory, you’ll see a line named “Prototype”. That is the object that’s going to be created each time this is called. Go into that object and place the sprite of your wanting inside to get what you desired.

Like @Gmanicus writes, your code looks good. Just add a sprite to the game object you assigned to your factory and you’re good. You might also look into using a repeating timer instead of decreasing a counter in update(). There’s a timer extension in our Asset Portal.