God Bless Lua
Yesterday I implemented a "load/save game"-system in WikiAdventure. It's actually really more of a "continue game/don't continue game"-system, but that's beside the point.
Anyway, I'm using the Lua scripting language for in-game scripting, so I have no idea which variables will be created and which to save etc.. Tricky you say? Yes, but I did it, and I'm not selfish, so I'm going to share my incredibly complex algorithms with you.
The first thing you need is the Lua state object. This is how I've defined mine:
LuaStateOwner m_oLuaState;
To save a game you do the following:
m_oLuaState->DumpGlobals( "savegame.file" );
To load the saved game you do the following:
m_oLuaState->DoFile( "savegame.file" );
Pretty damn neat, huh? Just another reason why I loooove Lua :)
Anyway, I'm using the Lua scripting language for in-game scripting, so I have no idea which variables will be created and which to save etc.. Tricky you say? Yes, but I did it, and I'm not selfish, so I'm going to share my incredibly complex algorithms with you.
The first thing you need is the Lua state object. This is how I've defined mine:
LuaStateOwner m_oLuaState;
To save a game you do the following:
m_oLuaState->DumpGlobals( "savegame.file" );
To load the saved game you do the following:
m_oLuaState->DoFile( "savegame.file" );
Pretty damn neat, huh? Just another reason why I loooove Lua :)
0 Comments:
Send en kommentar
<< Home