Page 2 of 3

Re: How to build a save system

Posted: Tue Nov 29, 2011 6:22 am
by ivan
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.

Re: How to build a save system

Posted: Tue Nov 29, 2011 9:11 am
by miko
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.
You can also study the sources of BoxBreaker:
http://love2d.org/forums/viewtopic.php? ... 7&start=20

Re: How to build a save system

Posted: Tue Nov 29, 2011 10:58 am
by coffee
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 save system

Posted: Wed Nov 30, 2011 12:46 am
by Lord Uber Dowzen
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.
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.
miko wrote: You can also study the sources of BoxBreaker:
http://love2d.org/forums/viewtopic.php? ... 7&start=20
Great, I'll take a look at that too. Thanks!
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.
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...

Re: How to build a level file format

Posted: Wed Nov 30, 2011 11:26 pm
by LuaWeaver
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.

Re: How to build a level file format

Posted: Thu Dec 01, 2011 12:52 am
by coffee
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.
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.

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 },
 
However saving is not the problem that' Lord Uber needs to work for now. He needs rewrite his engine and correctly generate or load a map for now.

Re: How to build a level file format

Posted: Thu Dec 01, 2011 1:32 am
by kikito
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.

Re: How to build a level file format

Posted: Thu Dec 01, 2011 2:04 am
by Taehl
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.

Re: How to build a level file format

Posted: Thu Dec 01, 2011 8:14 am
by miko
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.
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.

Re: How to build a level file format

Posted: Thu Dec 01, 2011 9:23 am
by coffee
miko wrote:
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.
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.
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. Hmmm ;)