   [web] Storing levels in a javascript game
  So, I have a level editor for a platformer. It can easily load and save levels in its raw form, no problem with that. The problem is that now I have to store them as well in some way that can be easily used with a &#106avascript game.Before going in, I want to remark that I'm storing a tilemap along with some header data. I decided to encode the tilemap as a string, with each tile being one character (with the current combinations of characters I have, I can have up to 64 different tiles). That part is fine.Right now, the level editor generates code such as follows (using code instead of source because the syntax "highlight" for &#106avascript is broken):function load_level_data_1(){    game.level_data[0] = new function() { return this };    game.level_data[0].width = 17;    game.level_data[0].height = 7;   game.level_data[0].layout =   "0000000000000000002220222022202220001001000100001000010012001220" +   "0100001001000001001000010012202210010000000000000000000";   game.level_data[0].coll =   "0000000000000000000000000000000000000000000000000000000000000000" +   "0000000000000000000000000000000000000000000000000000000";}(yes, the level editor breaks the strings into several lines =D)While I guess that works, it seems hackish to me. Hard-coding values isn't much of a trouble really as this is a program-generated file (so technically it isn't so hard-coded from my viewpoint), but I have the grip that each level is being defined into its own function. I tried creating an array and storing the functions in it, but for some reason it refused to recognise the existence of the array, despite other files can access the place where it's stored easily o_oDoes anybody have any suggestions? What I have works, but it's hackish in my opinion and I want to see if it can be improved first.   
  You might want to learn JSON..http://www.json.org/This could translate your data as such;{levels:[{width:170,height:7,layout:"002923....",coll:"00010023....."},{width:160,height:7,layout:"002923....",coll:"00010023....."}]}This basically represents an array of level objects Array([0] => Object('width' => 170, 'height' => 7...), [1] => Object('width' => 160', ...))Using JS or common libraries (prototype, jquery, dojo, etc) can be parsed into simple strings and reparsed into objects.Edit: Also with json you can have an item be a function.   ;  Er, good point, will look into converting the code into JSON =S But what worries me more is this:function load_level_data_1()Basically that it's being created as a global function. One that has to be referenced explicitly and not through an array or something.I just moved some things around and managed to get the game object finally working on that file (it's a generic object that stores all the global data of my game - yes, basically an improvised namespace =P). It sucks having to make a file exclusively to declare it, but oh well =/So now it basically looks like this (again, not JSON-ized =b):game.level_data[0] = new function(){    this.width = 17;    this.height = 7;   this.layout =   "0000000000000000002220222022202220001001000100001000010012001220" +   "0100001001000001001000010012202210010000000000000000000";   this.coll =   "0000000000000000000000000000000000000000000000000000000000000000" +   "0000000000000000000000000000000000000000000000000000000";   return this;}Will see if I can save it as JSON but I guess that this will do for now. Thanks =PEDIT: now levels look like thisgame.level_data[0] = {    width: 17,    height: 7,   layout:   "0000000000000000002220222022202220001001000100001000010012001220" +   "0100001001000001001000010012202210010000000000000000000",   coll:   "0000000000000000000000000000000000000000000000000000000000000000" +   "0000000000000000000000000000000000000000000000000000000"}=)   ;  Like he said, JSON is the way to go.