ERROR:GAMEOBJECT: The collection 'level2' could not be created since there is already a socket with the same name (SOLVED)

I’ve read through what feels like every other question topic about this issue - and still can’t see what I’ve done wrong. When trying to load my level2 collection, this error pops up.
Here is my code which posts to the main controller to load it:

function on_message(self, message_id, message, sender)
	if message_id == hash("collision_response") then
		Lsettings.coin_count = Lsettings.coin_count + 1
		sound.play("#coin_pickup")
		go.delete()
	end
	if Lsettings.coin_count == 4  and Lsettings.current_level == 1 then
		msg.post("main:/controller", "load level 2")
	end
end

Here is my code in the main script to load it:

	elseif message_id == hash("load level 2") then
		-- level 2
		msg.post(self.current_collection, "unload")
		msg.post("#level2_proxy", "load")
		self.current_collection = "#level2_proxy"

I have checked every other collection, and none of them have the property name level2 aside the actual level 2. Here is a screenshot of the search bar for ‘level2’


I’m probably missing something super dumb, please let me know.

“ERROR:GAMEOBJECT: The collection ‘level2’ could not be created since there is already a socket with the same name”

This can mean one out of two things:

  1. You are loading the same collection twice
  2. You have more than one collection loaded with id level2

I did a little bit of testing and resolved it through changing my code to post to the main controller, and it works now.
Fixed code:

local cooldown = 0
function update(self, dt)
	-- Update the cooldown timer
	if cooldown > 0 then
		cooldown = cooldown - dt  -- Reduce the cooldown timer by the time elapsed since the last frame
	end
end

function on_message(self, message_id, message, sender)
	if message_id == hash("collision_response") then
		Lsettings.coin_count = Lsettings.coin_count + 1
		sound.play("#coin_pickup")
		go.delete()
	end
	if Lsettings.coin_count == 4  and Lsettings.current_level == 1 and cooldown <= 0 then
		msg.post("main:/controller", "load level 2")
		cooldown = 100000
	end
end

I assume my code was probably trying to repeatedly send the message to the controller.

Ah, yes, you are right. The conditional check for coin count and current level will evaluate to true each time you receive a message. Adding a cooldown like you did, or even better a boolean flag, will a void the problem.

But you could also move the conditional check inside the “collision_response” like this:

function on_message(self, message_id, message, sender)
	if message_id == hash("collision_response") then
		Lsettings.coin_count = Lsettings.coin_count + 1
		sound.play("#coin_pickup")
		go.delete()
		if Lsettings.coin_count == 4  and Lsettings.current_level == 1 then
			msg.post("main:/controller", "load level 2")
		end
	end
end
1 Like