Newbie question (SOLVED)

Hi there! Nice to meet you all.

I’ve just started out with a small project to get the hang of Defold but I’ve come up against my first problem.

I want to create a grid in a set position on my screen, so I’ve created a factory and I’m writing the factory script. I want each line sprite to have a position property I don’t know if this is the correct way to do it but when I build my project this is the error I’m getting in the console

WARNING:GAMESYS: Maximum number of collisions (64) reached, messages have been lost. Tweak "physics.max_collisions" in the game.project file.

WARNING:GAMESYS: Maximum number of contacts (128) reached, messages have been lost. Tweak “physics.max_contacts” in the game.project file.
ERROR:GAMESYS: Sprite could not be created since the buffer is full (128). Increase the ‘sprite.max_count’ value in game.project
ERROR:GAMEOBJECT: Could not spawn an instance of prototype /main/V_borderLineGO.goc.

also this is my script code

go.property(“right_x”, 101)
go.property(“right_y”, 368)
go.property(“right_Pos”, msg.url())

go.property(“left_x”, 321)
go.property(“left_y”, 368)
go.property(“left_Pos”, msg.url())

function init(self)
factory.create("#V_border_factory", vmath.vector3(self.right_x, self.right_y, 1), nil, {}, 1)
factory.create("#V_border_factory", vmath.vector3(self.left_x, self.left_y, 1), nil, {}, 1)
end

function update(self, dt)
for i = 1, 10 do
self.id = tostring(i)
self.rightBorder_x = (self.right_x + 4) * i
self.rightBorder_y = (self.right_y + 22) * i
self.rightBorder_pos = vmath.vector3(self.rightBorder_x, self.rightBorder_y, 1)
factory.create("#V_border_factory", rightBorder_pos, nil, {}, 1)
end
end

1 Like

quick update, I have changed my code to this

go.property("right_x", 101)
go.property("right_y", 368)
go.property("left_x", 321)
go.property("left_y", 368)


function init(self)
	factory.create("#V_border_factory", vmath.vector3(self.right_x, self.right_y, 1), nil, {}, 1)

	factory.create("#V_border_factory", vmath.vector3(self.left_x, self.left_y, 1), nil, {}, 1)

end

function update(self, dt)
	for i = 1, 10 do
		-- self.id = tostring(i)
		self.rightBorder_x = self.right_x
		self.rightBorder_y = self.right_y - (22 * i)
		self.rightBorder_pos = vmath.vector3(self.rightBorder_x, self.rightBorder_y, 1)
		factory.create("#V_border_factory", self.rightBorder_pos, nil, {}, 1)
	end
	
	for i = 1, 10 do
		-- self.id = tostring(i)
		self.leftBorder_x = self.left_x
		self.leftBorder_y = self.left_y - (22 * i)
		self.leftBorder_pos = vmath.vector3(self.leftBorder_x, self.leftBorder_y, 1)
		factory.create("#V_border_factory", self.leftBorder_pos, nil, {}, 1)
	end
end

after build i can see the lines but I still get the collision errors, also the lines created in function init(self) and the ones created in function update(self, dt) do not look the same

Welcome to Defold!

You’re getting error messages about resources running out. The amount of resources allocated can be changed in game.project, however in this instance the issue lies elsewhere. You spawn borders in the update() function, which runs once every frame. This means (assuming 60 fps), you’ll be spawning 600 (x2) objects every second. I don’t think that’s what you want! It’s likely you want to spawn them in init() instead.

4 Likes

Nice it worked, not getting the errors after build, thank you so much for your help !

1 Like

Is there a way to handle running out of resource gracefully in a running game?
sys.set_error_handler() does not catch ‘WARNING:GAMESYS: Maximum number of collisions …’
Currently a game will start randomly malfunctioning. The tilemap collisions example in the manual does this quite easily (Tilemap collisions). It would be good to be able to do an auto-reset, stop the game or increase the size of the resource as needed. Is this currently possible?

No, not currently. And it doesn’t really align with our design philosophy of allocating everything upfront to be as performant as possible.