Ask coding questions

← Back to all posts
How do I access levels

I'm trying out Kaboom and I like the way the editor does my loading, but I don't understand how to access the levels.

Other Replit's seem to make everything a new scene and duplicate everything.
I'd like to load level data from "/level/mainLevel" array but when I've defined levels I can't use it in main.

I've tried loading <script src="level/mainLevel"><script> in the index.html as it looks like it all gets bundled into index.html anyway. However the loading scripts get refreshed each run (and it didn't work anyway).

I can't export default levels in the level/mainLevel as it won't let me use import in main.js (can't use imports outside of a module)

I think I'm missing something obvious.




Since mainLevel and main.js are separate files, you need to call an HTTP request to GET the file contents. More on that here. This will return a string that you can then parse however you deem fitting.