lua-users home
lua-l archive

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


well a straightforward solution in Lua would be (code not tested):

Cache = {}
function Load_Cached(name)
	if not Cache[name] then
		Cache[name] = Load_Animation("c:/animations/anim1.dat")
	end
	return Cache[name]
end

now you can do:

A1_door = Load_Cached("c:/animations/anim1.dat")

hope this helps,
Peter

-----Original Message-----
From: owner-lua-l@tecgraf.puc-rio.br
[mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Lamarche, Denis
Sent: Thursday, October 04, 2001 9:53 PM
To: Multiple recipients of list
Subject: Loading Game Resources


Hi, Im trying to make a game using Lua.  I have different sectors in my game
that I call rooms.  Each room has a script for it.  In each of these
scripts, I load/unload game resources(bmp) and do some room AI.  Right now I
am loading the resources like this:
A1_door = Load_Animation("c:/animations/anim1.dat")
--Load_Animation is a 'C' function that loads the animation data file
"c:/animations/anim1.dat" and returns an index to the array the animation
structure was assigned to (in C).

Now what is happening is that I start in room 1, and load an animation.
Then I move to room2 (and do whatever), and then move to room 1 again.  And
of course the animation is reloaded and assigned to a new index in the
array.  now there is two of the same animation in the array and the A1_door
var has the index of the second.  How can I make it so that when I go back
into room1 the second time, I dont reload the animation??  I want to keep
the animation loaded.  I've tried a hash table (in 'C') with the filename,
but what do I do when I want to create a new animation using the same
animation file as another anomation in the array.  I hope this makes sence.
How do you guys do it?

Note: when I use the term 'array' Im talking about doing it in 'C' language.

Denis Lamarche