Recently started programming again and have some questions.
Do I need to create one collection proxy for every level or can I use one collection proxy and tell it to load a specific level layout from a table?
I might be wrong. But if I need to do multiple collection proxys that means I will need to have the exact same code in multiple files with the only difference being the level layout.
Yes, you need to create a collection proxy for each level; You can’t change the proxy’s collection at runtime. I don’t see any reason why you would need to duplicate code, but it depends on what you want to do. You can have a table of all your proxy urls and post the “load” message to whichever one you want.
Thx. Solved it. It was possible to just use one collection proxy in my case.
I post a message after I have loaded my Play collection proxy that have all info i need for the gameplay.
elseif message_id == hash("proxy_loaded") then
msg.post(sender, "init")
msg.post(sender, "enable")
if sender.fragment == hash("Play") then
msg.post("play:/Loader#script", "level", {level = nextLevel})
end
end
In the other proxy i have this code:
if message.level == 1 then
map = {"Level1Data"}
elseif message.level == 2 then
map = {"Level2Data"}
end
Ahh, I see. So you are generating your level layout from a table of data? I was thinking you had pre-built levels in the editor as separate collections. I’m glad you solved it.
In this case you could use a table of tables like you said in your old post, and not have to use an elseif block for every level. So