lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> There are two differents issues in "saving a state".

> First, there is the simpler form of merely saving the information 
> required to resume a game, say, the rooms that were visited, 
> points and bonus, this kind of stuff. This is all very simple and 
> can be saved as a Lua program that mere assigns the required 
> values to global variables or to a table that is returned by the
> chunk or something.  Once this file is saved, the game can be 
> resumed by simply loading the program again, doing whatever 
> initializations are needed (eg. registering C functions and such) 
> and then loading the Lua file that was previously saved.
> For this simpler form, lua/test/save.lua can help.
> Lua has been designed for this kind of stuff, in fact.
Cool.  Save.lua has pretty much everything I need.  What part of 
lua's design makes it "designed for" saving stuff?

> Second, there is the harder form of saving *everything* in the 
> innards of Lua, including all strings and where Lua as executing 
> and such. This is much harder and I doubt that it's what is 
> needed.
> But perhaps I'm missing something here.
I realize I haven't explained a certain aspect of what I want lua
to do for my game.  I would like to define sequential scripted
commands whereby I can create a file that looks like the following:

function attack (target)
    if (not infiringrange(target))
	  -- execution of the lua function attack "stops" here until 
	  -- the attacking soldier has reached firing range
	      -- game execution (as well as lua reading other
		-- lua files) continues
	-- the soldier is now within firing range

In this simplistic example, I demonstrate something I haven't been
able to achieve with lua yet, that is blocking functions.  Is 
there a way to do this?  

One way I can think of is for my game to manually read the lua 
files line by line - every line would return to the game whether 
it's a "blocked" line or not, and what the condition of that 
block is (what game event causes it to unblock).  According to the
lua reference doc, you can only read an entire file, a string
or a buffer, but since lua 4.0 is reentrant, there's no saying
you can't read a file line by line.  Does this make sense?  Is
line reading (through a buffer maybe?) possible for lua?

At any rate, the reason I wanted to save the lua state innards 
(using the second form mentioned above) is because the player 
may want to save his game while his soldier is "moving to" 
his target.  Lua would then be in the middle of reading a file, 
possibly needing a save of the innards of the lua state.

If my game had the ability to read files line by line, however,
the game would only need to save the line number it was reading
at the time of the save, plus whatever gets saved by "save.lua".

I've rambled a bit, but hopefully you understand my questions.

Thanks for all your help!
Falko Poiker
Relic Entertainment Inc.