Hey all,
My little brother makes Flash games and was having some trouble coming up with a way of having his level editor create strings for users to send to each other (for custom levels). So I wrote this little Javascript to do the task.
It works in any scenario where you only have objects of certain types at certain locations (i.e. you can’t use it to save parameters or anything). Pretty much it stores all object information in 4 characters, where the first character is the type and the next 3 characters represent the position. In this iteration, it can only save objects that exist in a world where width*height <= 238,328, but you could pretty easily increase that if you needed to by allowing more characters. It only uses uppercase, lowercase, and digits, so essentially it’s like a base 62 number system.
It also has a simple check digit added on at the end which is the total of all the digits mod 62 so that users can’t go editing the string to get whatever they want.
Even though it’s in Javascript, I figured it might be useful for some of you. I will probably convert it to Java at some point and use it in some of my simpler games. It will adapt great to grid-based environments.
http://www.otcsw.com/LevelSaveTest.html
(Just view source to see it)
Also the extremely verbose and somewhat obvious comments are meant to try to get my brother (who is not very experienced) to understand it. Also sometimes doing things like string = string + “foo” instead of string += “foo” are for that reason also.