Skip to main content
gamedev.net
🔒 Locked

Lua: Using multiple scripts. [possibly solved]

Started by Richy2k 1 reply 4.1k views
Original Post
Richy2k
Richy2k
Just getting Lua integrated into my game at the moment, is going pretty great, got all my utility functions sorted, started on my interface to the engine, and ported over vectors and other such data structures to work inside Lua. I have one problem left - Loading/unloading of multiple scripts. At first glance I figured it would be easy - start of a mission load in scripts for entities that exist, the mission script, and what not else so all functions are availible to the game. I can not seem to load up multiple scripts in this way, atleast trying to use luaL_loadfile multiple times does not work, and I have failed to find anything on the internet to point me in the right direction so far - severe lack of Lua stuff out there. I considered multiple VMs, one per entity as Silvo suggested in another post, as this would mean I wouldn't need to mess about too much with metatables, or even object orientation in Lua at all. But this would mean I need to expose all the functionality I would like every time a lua_State is created, which I'm sure would be noticable performance wise. Has anyone else tried to do this sort of thing? Essentially I would like all entities that can exist to have their own script defining its behavoir, so dropping new entities/triggers into the world isn't a hard job. Communication between entities and the gui is done via a string based message system inside the game engine itself, which allows the gui to send commands to entities, triggerable brushes in the world to broadcast messages to all entities, so on. Thanks. [Edited by - Richy2k on February 17, 2007 9:30:01 AM]
rileyriley
rileyriley
I have no problem calling loadfile multiple times~ what are your symptoms of "not working?"

On another note, though, if you load the SAME file multiple times, it's likely that you're going to overwrite some data unless you're pretty careful. I load a file that can generate new entities with a function call. That way I don't have to load a file again, I just call the lua function from C++ again.
--Riley
Richy2k
Richy2k
If i have one lua script with 2 functions in, load script, call both functions - it works. If I have 2 scripts, each one with one of the functions in it - load both, call both, it breaks trying to call the function inside the first script loaded.

This made me kind of assume I can not do this [sad]

Edit:

Seem to have it working. Didn't realise after loading each script you needed to call "lua_pcall( pLuaState_, 0, LUA_MULTRET, 0 );". Looks like I might need to go read up a little more.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.