Support for saving/loading the Lua state?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Support for saving/loading the Lua state?
For saved games? Unless anyone has any really good ways of doing this?
Re: Support for saving/loading the Lua state?
I don't think there's a way to save or load a Lua state, but I'm not sure you have to go that far. If you can represent the state of the game using variables (i.e. you don't need to remember the state of the stack or the program counter) then you can just save and load the content of the variables.
You can do it in many ways. One example is here: http://lua-users.org/wiki/PersistentTables (note that it's for Lua 4, if you need help with that I can probably come up with a Lua 5.1 implementation).
You can do it in many ways. One example is here: http://lua-users.org/wiki/PersistentTables (note that it's for Lua 4, if you need help with that I can probably come up with a Lua 5.1 implementation).
Re: Support for saving/loading the Lua state?
Thanks for the link I'll look into this, but I'm talking about it's going to be difficult to save entity's and other variables which reference to an entity (each entity has a unique index).
-
- Party member
- Posts: 101
- Joined: Mon Aug 11, 2008 5:19 am
Re: Support for saving/loading the Lua state?
Structuring your data such that it is reasonable to save and load your game needs to be an early part of your planning. If you're having trouble, I think it would be best to restructure your program - it's the only way to deal with the save/load issue properly down the line.
--Mr. Strange
--Mr. Strange
Re: Support for saving/loading the Lua state?
It's possible to save the entire Lua VM to a file, but it wouldn't do us much good. Textures in OpenGL would vanish, sound data would not persist, etc.
Re: Support for saving/loading the Lua state?
Also, think about how much space would be wasted. In a simple game where you only need to remember what level someone is on, then it would always be better to just save a single variable than to dump the whole VM. If you want to apply zen to programming, think of saving games in this fashion:
What is it, in essence, that defines this game session as a unique experience, trapped in the confines of a strict universe?
That should give you the variables you need to save/load games.
What is it, in essence, that defines this game session as a unique experience, trapped in the confines of a strict universe?
That should give you the variables you need to save/load games.
Now posting IN STEREO (where available)
Re: Support for saving/loading the Lua state?
Hey rude, please add this to Love
http://luaforge.net/projects/pluto/
http://luaforge.net/forum/forum.php?forum_id=1518 Pluto 2.0 (final) looks bloody amazing.
(or tell me how to compile it and use it as a module )
http://luaforge.net/projects/pluto/
http://luaforge.net/forum/forum.php?forum_id=1518 Pluto 2.0 (final) looks bloody amazing.
(or tell me how to compile it and use it as a module )
Re: Support for saving/loading the Lua state?
Regarding saving the Lua state, I've found these posts (quite old):
http://lua-users.org/lists/lua-l/2000-07/msg00134.html
http://lua-users.org/lists/lua-l/2003-11/msg00003.html
Don't know if they are still relevant. In any case I wouldn't recommend saving the entire VM even if it's possible - that's what I call an overkill (like creating a core dump just to store a few variables).
http://lua-users.org/lists/lua-l/2000-07/msg00134.html
http://lua-users.org/lists/lua-l/2003-11/msg00003.html
Don't know if they are still relevant. In any case I wouldn't recommend saving the entire VM even if it's possible - that's what I call an overkill (like creating a core dump just to store a few variables).
Re: Support for saving/loading the Lua state?
The way I set it up, a "save" file is just a single line of Lua code saved as text to a file, which returns a table that holds all the info for that level. Then you can just go dofile("levelname"), and you've got the level back.
Re: Support for saving/loading the Lua state?
The problem is, that then loads the level from the start.
I want it to load exactly how it was, entities with their exact position, angles, and any custom info set for them.
If Rude could make that addon I suggested a few posts up come with Love by default, that'd be awesome. (Or if someone could tell me how to compile it myself and include it with my game).
I want it to load exactly how it was, entities with their exact position, angles, and any custom info set for them.
If Rude could make that addon I suggested a few posts up come with Love by default, that'd be awesome. (Or if someone could tell me how to compile it myself and include it with my game).
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest