loading levels

Monkey Targets Forums/HTML5/loading levels

Yoda(Posted 2011) [#1]
Is there any way I can load files during runtime, in order to load level-data for a game?

I don't want to include all the level-data in strings in the code.


skape(Posted 2011) [#2]
EDIT: Oops, just realized that this was in the HTML5 section--part of what I wrote still applies. Various additional HTML5 methods have been discussed.

Hi, check out the os module, particularly LoadString() for the basics. You can also take a look at warpy's JSON example in the "bananas" folder (for one, there are other examples out there), for some ideas, or the Monkey Code section of this form, which has various useful classes...


impixi(Posted 2011) [#3]
You could write a TextFile class in JavaScript that utilizes XMLHttpRequest. Something like this (UNTESTED):

textfile.js


And the monkey code that hooks into it might be something like this (UNTESTED):



This won't run locally (due to browser security checks).