Hi Lord Uber Dowzen.
Like coffee pointed out your topic title is a bit imprecise.
"Save system" usually refers to loading and saving user preferences, hiscores and progress.
What you're designing in this case I would call the "level file format".
A while ago a wrote someting you mind find useful:
http://love2d.org/forums/viewtopic.php?f=4&t=3323
It basically shows you how to save tilemaps as an ASCII file which is (usually) easier to edit than lua tables or serialization.
How to build a level file format
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: How to build a save system
You can also study the sources of BoxBreaker:ivan wrote:Hi Lord Uber Dowzen.
Like coffee pointed out your topic title is a bit imprecise.
"Save system" usually refers to loading and saving user preferences, hiscores and progress.
What you're designing in this case I would call the "level file format".
A while ago a wrote someting you mind find useful:
http://love2d.org/forums/viewtopic.php?f=4&t=3323
It basically shows you how to save tilemaps as an ASCII file which is (usually) easier to edit than lua tables or serialization.
http://love2d.org/forums/viewtopic.php? ... 7&start=20
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Re: How to build a save system
Your tile engine code needed a bit of work so I accidentally started organizing and improving (I think).
But then when I tried to load a full map table I noticed that you were table addressing and drawing the map at 0,0 and not at 1,1 ( natural starting value assigned on tables). So that complicated a lot my plans and I wanted to modify/adjust ALL your engine but neither I had more time neither this is my project and can't take you the pleasure of you doing it. ;D
So anyway take a look (or not) of the things I changed trying to improving it.
What I did:
- Changed placement of degug info from above map
- Instead of hardcoding 16 everywhere I created tileWidth and tileHeight
- Organized your code a bit creating some functions
- Instead of moving camera the hardcoded 8 pixels altered to tileWidth,tileHeight
- Added Wheelmouse to change the tile value
What I think you should continue to do:
- Adjust all your engine to work with map table starting at 1,1. That means start for cycles at 1 and adjust calculations and drawing to something like x*tileWidth-tileWidth, y*tileHeight-tileHeight.
- Load a full table "map = { values }" in map.lua directly instead of assigning piece by piece like you were doing.
Ahh... In map.lua you hadn't to map[0] = { }, map[1] = { } because you already were doing that to all rows in main.lua. I removed that lines in map.lua and you can see no need of do that...
So take a look too of Ivan and miko tutorials proposals and keep working. We are here to continue to help.
But then when I tried to load a full map table I noticed that you were table addressing and drawing the map at 0,0 and not at 1,1 ( natural starting value assigned on tables). So that complicated a lot my plans and I wanted to modify/adjust ALL your engine but neither I had more time neither this is my project and can't take you the pleasure of you doing it. ;D
So anyway take a look (or not) of the things I changed trying to improving it.
What I did:
- Changed placement of degug info from above map
- Instead of hardcoding 16 everywhere I created tileWidth and tileHeight
- Organized your code a bit creating some functions
- Instead of moving camera the hardcoded 8 pixels altered to tileWidth,tileHeight
- Added Wheelmouse to change the tile value
What I think you should continue to do:
- Adjust all your engine to work with map table starting at 1,1. That means start for cycles at 1 and adjust calculations and drawing to something like x*tileWidth-tileWidth, y*tileHeight-tileHeight.
- Load a full table "map = { values }" in map.lua directly instead of assigning piece by piece like you were doing.
Ahh... In map.lua you hadn't to map[0] = { }, map[1] = { } because you already were doing that to all rows in main.lua. I removed that lines in map.lua and you can see no need of do that...
So take a look too of Ivan and miko tutorials proposals and keep working. We are here to continue to help.
-
- Prole
- Posts: 18
- Joined: Wed Sep 29, 2010 3:02 am
Re: How to build a save system
Cool, thanks for that. Sorry about the topic title but I was planning on working on the level file and then moving onto saving character location etc when I moved onto doing the actual game part. I'll rename the topic (if I can) to avoid further confusion. Thanks for the link, looks helpful.ivan wrote:Hi Lord Uber Dowzen.
Like coffee pointed out your topic title is a bit imprecise.
"Save system" usually refers to loading and saving user preferences, hiscores and progress.
What you're designing in this case I would call the "level file format".
A while ago a wrote someting you mind find useful:
http://love2d.org/forums/viewtopic.php?f=4&t=3323
It basically shows you how to save tilemaps as an ASCII file which is (usually) easier to edit than lua tables or serialization.
Great, I'll take a look at that too. Thanks!miko wrote: You can also study the sources of BoxBreaker:
http://love2d.org/forums/viewtopic.php? ... 7&start=20
Awesome, I'll take a look at your code and implement the stuff you've mentioned. I think I need to start a to-do list...coffee wrote:Your tile engine code needed a bit of work so I accidentally started organizing and improving (I think).
But then when I tried to load a full map table I noticed that you were table addressing and drawing the map at 0,0 and not at 1,1 ( natural starting value assigned on tables). So that complicated a lot my plans and I wanted to modify/adjust ALL your engine but neither I had more time neither this is my project and can't take you the pleasure of you doing it. ;D
So anyway take a look (or not) of the things I changed trying to improving it.
What I did:
- Changed placement of degug info from above map
- Instead of hardcoding 16 everywhere I created tileWidth and tileHeight
- Organized your code a bit creating some functions
- Instead of moving camera the hardcoded 8 pixels altered to tileWidth,tileHeight
- Added Wheelmouse to change the tile value
What I think you should continue to do:
- Adjust all your engine to work with map table starting at 1,1. That means start for cycles at 1 and adjust calculations and drawing to something like x*tileWidth-tileWidth, y*tileHeight-tileHeight.
- Load a full table "map = { values }" in map.lua directly instead of assigning piece by piece like you were doing.
Ahh... In map.lua you hadn't to map[0] = { }, map[1] = { } because you already were doing that to all rows in main.lua. I removed that lines in map.lua and you can see no need of do that...
So take a look too of Ivan and miko tutorials proposals and keep working. We are here to continue to help.
Re: How to build a level file format
It does not owrk. You never opened the file, and when I alter the code, so that file=love.filesystem.newFile("map/map2.lua"), and then I use file:open("w") file:write(strg) it returns with the erorr "File not open". Sorry, it doesn't work, and I can't fix it.
"your actions cause me to infer your ego is the size of three houses" -finley
Re: How to build a level file format
which version you downloaded and tested? the old "awesome tile engine" right? that version as I noticed had some problems. If you open my "altered version", add more some values in the improvised editor, click "s" and go to the default saving LOVE directory you will see a dir called "map" that saves a newmap.lua. I did a quick check and saving it's ok.LuaWeaver wrote:It does not owrk. You never opened the file, and when I alter the code, so that file=love.filesystem.newFile("map/map2.lua"), and then I use file:open("w") file:write(strg) it returns with the erorr "File not open". Sorry, it doesn't work, and I can't fix it.
I got this so even that the saving routine is not adapted to start at 0,0 (what is not natural for a table) starts at 1,1 so as you can see the saving routine dont catch the four "4" values loaded by default at start (in top-west zone of map) but only one and that makes sense, it's the +1,+1 offset. So saving is working well. Also all that nils in map it's because the load routine of the example dont load a full table but only 4 values and Lord Uber made an empty map[x]= { } routine to fill all map rowns. The code also dont have now a complete map. So in "my version" saving is already working well and also load is fine.
Code: Select all
map = {
{ 4, nil, 9, 9, 9 },
{ 9, 9, nil, nil, 9 },
{ nil, 9, nil, nil, 9 },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, 9, nil },
{ nil, nil, 9, nil, 9 },
{ nil, nil, nil, 9, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, 9, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, nil, nil },
{ nil, nil, nil, nil, nil },
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: How to build a level file format
I would use any other thing instead of nil on the "empty" tiles.
Nil makes some traversing functions (for example ipairs) go wonkers.
I recommend using 0, "" or false for those.
Nil makes some traversing functions (for example ipairs) go wonkers.
I recommend using 0, "" or false for those.
When I write def I mean function.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: How to build a level file format
Using nil will also make the # operator not work the way you want it to.
That being said, I personally like using nil for non-tiles, but I also use it with careful numeric "for" loops instead of pairs or ipairs.
That being said, I personally like using nil for non-tiles, but I also use it with careful numeric "for" loops instead of pairs or ipairs.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: How to build a level file format
Me too. Nil frees memory, all the other values are stored in memory. With large maps, it can make a difference - not only such a code takes less memory, but also is faster - there is no additional object which garbage collector traverses when trying to free resources. Still, for practical situations the difference is really small, so this is not critical anyways.Taehl wrote:Using nil will also make the # operator not work the way you want it to.
That being said, I personally like using nil for non-tiles, but I also use it with careful numeric "for" loops instead of pairs or ipairs.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Re: How to build a level file format
Well Lord isn't yet still on track with his engine spite the advices but I'm glad that you entered in that NIL rambling. That's a good tip for me miko (and Taehl) thank you. Why? because in my project I'm using map layers and I was filling "air"/"empty" tiles with a pre-determined numeric value as kikito like to do. My map isn't big for now but actually for memory saving/optimizing I could instead fill it with NIL's and "trap" the NIL errors. Hmmmmiko wrote:Me too. Nil frees memory, all the other values are stored in memory. With large maps, it can make a difference - not only such a code takes less memory, but also is faster - there is no additional object which garbage collector traverses when trying to free resources. Still, for practical situations the difference is really small, so this is not critical anyways.Taehl wrote:That being said, I personally like using nil for non-tiles, but I also use it with careful numeric "for" loops instead of pairs or ipairs.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 2 guests