Level data?
Monkey Forums/Monkey Programming/Level data?
| ||
What would be the best way to store level data in monkey? I have this game with about 100 levels to be made -- each level has obstacles (about 10 different 'types' of obstacles). I need to place these obstacles on the level when it loads. |
| ||
I would say a SQLite3 database is the best way to store application data. Firefox, SeaMonkey, and many other browsers use also a SQLite3 database to store bookmarks and other settings. SQLite3 doesn't need any installation, and you can embed the SQL engine in your code. It's also faster than MySQL, and it comes with a nice visual editor to create databases, tables, queries and populate them with data. I think I will make a Monkey module for SQLite3, since I need it for my games and apps too. Since it comes with full source code, it would be possible to make it work on all targets also, but of course first comes Android, then Linux, and then the rest (although Windows code would be basically identical with Linux) :) Then there are also commercial add-ons for SQLite3 to add encryption, but I can do that also for free, using TwoFish. It's the most secure and fastest encryption I know of, and it's free. |
| ||
SQLite is a little bit of overkill for simple level datas. What about XML or a simple custom binary format? |
| ||
I have my levels stored in an array at the moment as there is no cross platform file system as of yet. Works ok for the type of game I am doing (2D platformer) but might not be useful for other types of game. |
| ||
I use SQLite databases for all my games. So there! Cheers Charlie |
| ||
I think I'll go with a 1D array. XML or a database just seems like overkill. It's just a linear series of obstacles(or no obstacle represented by a 0) So something like [0,0,1,1,0,2,2,0] But my question is, is there a data system like in bmax? Something like, Data ------- (and then I believe there was a restoredata function) Or do I just create a massive list of 100+ 1D array variables? Is there a better way to do this? |
| ||
You can make level data with an array such as:Global Levels:=[ 3,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3, 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3, 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3, 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3, 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,5,0,0,0,3, 3,1,1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,4,1,4,4,4,4,1,1,1,1,1,1,1,1,3, 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3, 3,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3, 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,0,5,0,0,0,0,0,0,0,0,0,3, 3,1,1,1,1,0,0,0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,0,0,0,3, 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,3, 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3, 3,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,3,3,3,4,4,4,4,4,1,1,1,3, 3,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,3, 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3, 3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3] And then just read the data with something like: Local block:Int For Local y=0 To 15 For Local x=0 To 31 block=ROOMS[((y*32)+x)] DRAWblock(block,x*16,y*16) Next Next |
| ||
BigAnd -- That's what I ended up doing instead of 100's of different arrays. Thanks! |
| ||
LoadString() works well too if you don't want to embed your level data. Use myString.Split( "~n" ) to create an array of level data. (see the LoadString modules reference for a short example) |
| ||
Another question. I'm making a game (main target HTML5 for now). The idea is to 'update' the levels adding new ones in the time. First problem: LoadString 'reads' the .txt file and 'includes' *every* .txt file present in the main.js file. This means you can 'add' anything new to you game... Considering the on-line nature of HTML5 target is quite limited! (You need to 'update' all the main.js every time). I understand this limit - in part - on a 'mobile' platform as Android or iOS where content must be checked and so on. I'm looking for a solution (maybe HTML5 only), via some js magic... WIP Cheers |
| ||
You can perhaps use the AJAX module to fetch data from a database? http://www.monkeycoder.co.nz/Community/posts.php?topic=137 |
| ||
Thanks, it seems a solution. Do you know how to use it? I get an error about 'Overriding method does not match any overriden mothod'... PS: I think I've setted up everything on my system to test the 'getURL' function. I have - in local - an Apache server+PHP+Mysql. To test I've made a simple .php file <? $code=$_GET["code"]; echo "Code: {".$code."}<br>"; ?> So when I open http://localhost/gra10/html5/Level/getlevel.php?code=222 I see a page that reports "Code: {222}" - as expected. In the Monkey source code I changed streams.getUrl("http://localhost/gra10/html5/Level/getlevel.php", "?code=100" ) Any hints? I'm doing something wrong? There's some error with V32/1.03? |
| ||
I've been impressed with SQlite3 lumooja, could you please tell a little more about how Monkey could work with those databases? It seems it will be a must at the moment someone wants to do something serious with monkey :) thanks a lot in advance! |
| ||
About the error: I think I've resolved. See the thread about Async by Indiepath http://www.monkeycoder.co.nz/Community/posts.php?topic=137 Thanks |
| ||
I will make a SQLite3 module for Monkey this weekend. It shouldn't be much work, if I only expose a few essential commands, like submitting a SQL query and getting the results. |
| ||
wow lumooja! impressive! :) so if I would like to have a list of players of my game, this is the way in which I should work? I mean, learning how sqlite3 works and studying your module? Thanks so much lumooja ;) |
| ||
You should use SQL only for loading and saving the game state, and loading/saving dynamic content of course, like positions of objects. All data loaded from the SQL database should be kept in Maps, Lists and Stacks in the Monkey memory. |
| ||
Since WEB SQL (SQLite) specification is no longer being worked on by W3C I would recommend using AJAX and server-side databases when using HTML5. “This specification has reached an impasse: all interested implementors have used the same SQL backend (Sqlite), but we need multiple independent implementations to proceed along a standardisation path. Until another implementor is interested in implementing this spec, the description of the SQL dialect has been left as simply a reference to Sqlite, which isn’t acceptable for a standard. Should you be an implementor interested in implementing an independent SQL backend, please contact the editor so that he can write a specification for the dialect, thus allowing this specification to move forward.” |
| ||
Lumooja - Any progress on a SQLite library? Or is anyone else working on one?I'm trying to figure this out. |
| ||
@Lumooja - For all Targets? *.* |
| ||
FYI - WP7 Mango update contains the ability to access SQLCE databases. Not sure how it works as yet but is supposed to be available. |
| ||
I will make a database controller soon allready made one, just need to translate it to monkey. |