Skip to main content
gamedev.net
🔒 Locked

Interfacing scripting engine with game engine

Started by BradDaBug Sep 6, 2003 at 6:54 PM 2 replies 500+ views
Original Post
BradDaBug
BradDaBug
I''ve added Lua scripting to my game engine, but I''m not sure how to completely interface the two together. I want to make it where the scripts basically control all the game logic. That''d mean there''d be a LOT of functions my game engine would need to export for the scripts to use. They''ll also have lots of different uses, like a lot will be used to init and shutdown the engine itself, some used for AI, some used for physics, some for loading and unloading resources, etc. How do I manage all those functions? Do I put them in one giant .cpp file? Or do I seperate each general area into it''s own .cpp file, like the loading and unloading functions go in script_engine.cpp and AI functions go into script_ai.cpp? And what about different types of entities needing different AI functions? Like giant death stomper robots need their own functions and alien chickens will need their own; how to I manage these?
I like the DARK layout!
BradDaBug
BradDaBug
I think each object will define the scripting functions it needs in its module (its .cpp file) and all the functions will be defined in a giant header, scripts.h or something.

Another question I have is how do I create objects (people, rockets, houses, etc) in the script? Right now I''m thinking about having some kind of CreateObject(int type) function my scripts can call. Then that function goes into a giant switch and creates the right object based on ''type.'' Then the function will return a ''handle'' (probably just an int storing the address of the object) that the script then has to keep up with. Are there any problems with this I haven''t thought of?

I''d like to be able to define new object types in the script instead of having them hard coded in the game engine, but I don''t know how I''d do that in the script. Just have some basic simple "templates" (building, plant, biped, quadriped, flying thingy, etc) to build on? And if the object needs special code i just put it in the script?

And one more thing, I''d like to make the AI with scripts, so each object will have some function in the script it calls that''ll be its "brain." Would that be too slow?

Oh, and should I put the scripting engine thing in its own thread so it doesn''t slow down the rest of the engine? I guess I''d only need one thread for it since Lua 5 does concurrency on its own. Isn''t that right?
I like the DARK layout!
nonnus29
nonnus29
I''m doing the int CreateObject(int type) method; the game engine stores a vector of gameobjects which is the parent class of everything in the game, this function returns the index of the gameobject in the vector. Then I can do something like this in the script;

platform1=CreateObject(PLATFORM)

ObjectSetPosition(platform1,x,y)
ObjectMoveTo(platform1,x,y)

you get the idea.

Topic Locked

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

Sign in to reply to this topic.