Have a error here where it says The collection /main/stage1-1.collectionc could not be enabled since it is already. Message 'enable' sent from game:/boundary#boundary to main:/controller#stage1-1."

controller.script code

function init(self)
	-- Make sure stage1-1 starts disabled (if needed)
	msg.post("main:/controller#stage1-1", "load")
	
end

function on_message(self, message_id, message, sender)
	if message_id == hash("enable_stage1_1") then
		msg.post("main:/controller#stage1-1", "enable")
		
	elseif message_id == hash("disable_stage1_1") then
		msg.post("main:/controller#stage1-1", "disable")
		
	elseif message_id == hash("enable_stage1_2") then
		msg.post("main;/controller#stage1-2", "enable")
		
	elseif message_id == hash("disable_stage1_2") then
		msg.post("main:/controller#stage1-2", "disable")

	elseif message_id == hash("enable_stage1_3") then
		msg.post("main:/controller#stage1-3", "enable")

	elseif message_id  == hash("disable_stage1_3") then
		msg.post("main:/controller#stage1-3", "disable")
	end
end

also the boundary script code

function on_message(self, message_id, message, sender)
	if message_id == hash("collision_response") and message.group == hash("player") then
		msg.post("main:/controller#stage1-1", "enable")
		msg.post("game:/valley#stage1", "disable")

	elseif message_id == hash("collision_response") and message.group == hash("player") then
		msg.post("main://controller#stage1-2", "enable")
		msg.post("game://controller#stage1-1", "disabld")
		-- messages the controller scrip to not load the previous level

		local player_spawn_position = vmath.vector3(100, 200, 0) -- sets the spawn of the player in the next level
		go.set_position(player_spawn_position, "player") --same as above
	end	
end

My guess is that this is the problem. You get multiple “collision_response” and enable the same collection more than once?

1 Like

yes i belive it is that because when i want to move from level to level, i want the previous level to be disabled as in not loaded anymore, so that the next level can then be loaded but when i do it for stage1-1 and I try to move on i cannot.
I belive I should set a collision object where when the player hits the boundary of stage1-1, it loads stage 1-2 and so on and so forth however, it might cause redundant code and errors like the one above. Furthermore, that part of the code is used when upon hitting the boundary of the 1st stage, it loads the next stage (stage1-1) but after hitting stage 1-1s boundary it gives the error.

I would recommend that you track the state of each collection, perhaps something like this:

function on_message(self, message_id, message, sender)
	if message_id == hash("enable_stage1_1") then
		if not self.stage1_1_enabled then
			msg.post("main:/controller#stage1-1", "enable")
			self.stage1_1_enabled = true
		end
	elseif message_id == hash("disable_stage1_1") then
		if self.stage1_1_enabled then
			self.stage1_1_enabled = false
			msg.post("main:/controller#stage1-1", "disable")
		end
	end
end
1 Like

should i do that for my controller script or my boundary script

From the controller script. It is recommended to have a centralized place to load and unload collections. The controller script should be somewhere in the main/boostrap collection so that it doesn’t get unloaded.