Issues with loading collections

My game loads a collection to show the ending screen when the score is 2, however this error keeps popping up. I have had no issues with loading or unloading any other collections, even though they are all done in the exact same way as this collection.

ERROR:GAMEOBJECT: The collection 'ending_something' could not be created since there is already a socket with the same name.
ERROR:GAMEOBJECT: AcquireResources NewCollection RESULT_OUT_OF_RESOURCES
WARNING:RESOURCE: Unable to create resource: /main/collections/ending_something.collectionc: OUT_OF_RESOURCES
ERROR:GAMESYS: The collection /main/collections/ending_something.collectionc could not be loaded.
ERROR:GAMESYS: The collection /main/collections/ending_something.collectionc could not be unloaded since it was never loaded. Message 'unload' sent from main:/controller#main to main:/controller#ending_proxy.

I have checked all of the IDs and none have the same name as ‘ending_something’
I can’t understand why this is going wrong, any help would be appreciated!

For me it looks like you are trying to load the same collection twice.
Make sure you call load method (or send load message) only once.

Is it possible to send the message to load a collection to a loader script from multiple script, based on events that happen? not simultaneously obviously, but depending on conditions one script could send the message or a different script could send the message?

Yes. It is often the case that the game has a single “controller.script” that deals with loading the correct scene (e.g level or pause menu etc).

i still can’t seem to find a problem.

this is the code that messages the loader script


function update(self) 
	-- when two correct answers the game is complete - will be increased to five
	if self.correctAnswers == 2 then
		msg.post("main:/controller", "show ending screen")
	end
end

this is the code from the loader script that should load the collection

elseif message_id == hash("show ending screen") then
		-- ending screen
		msg.post(self.current_collection, "unload")

		msg.post("#ending_proxy", "load")
		self.current_collection = "#ending_proxy"

	end

can anyone see any reason why this wouldn’t work?

You’re firing off the “show ending screen” message in the update() function, with no way for it to stop after the first message. You need to ensure that message is only sent once, otherwise you’ll see some unintended behaviour.

Some examples, not knowing your project’s structure:

function update(self) 
	-- when two correct answers the game is complete - will be increased to five
	if self.correctAnswers == 2 then
		msg.post("main:/controller", "show ending screen")
		self.correctAnswers = 0
	end
end

Or:

function update(self) 
	-- when two correct answers the game is complete - will be increased to five
	if self.correctAnswers == 2 and not self.endingScreenTriggered then
		msg.post("main:/controller", "show ending screen")
		self.endingScreenTriggered = true
	end
end
1 Like

i changed it so that the function wasn’t an update function and was called elsewhere in the code, thankyou for your help!

2 Likes

Yes, doing the check when the score is incremented makes much more sense and I presume that’s what you ended up doing.

1 Like