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
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
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.