Sign in to follow this  
staticVoid2

when to use scripts.

Recommended Posts

my attention is slowly turning towards implementing a virtual machine for my game engine now that I have mostly finished the basics of graphics, I have been playing with a few ideas as to when and how scripts should used, first I thought I would just define a few functions in a script and maybe attach it to an object in which the object could use these functions as callbacks for certain tasks the object is carrying out, I then thought why not use these attched scripts to contain state information about the object and attach the script to a base object from which every object in the game would be derivied from, the problem is that now the game could (possible) be implemented fully in a scripting language. I want to know how far should you implement features of your game in C/C++ (or other) and what parts should you implement in script? for e.g. say I wanted an elevator in my game, should I create an elevator class/interafce, something like:

class IElevator : public GameObject
{
public:

   virtual void move_to_floor(int floor) = 0;
   virtual void close_doors() = 0;
   virtual void open_doors() = 0;
};


or should I attach a script to the base object? then for each instance of the script I could make low level calls like PlayAnimation(this, "Open_Doors"); etc. for opening closing doors from within the script, also save state information within the script like which floor the elevator is on etc. ?

Share this post


Link to post
Share on other sites
If you do take the script route, you could handle it so that your prefabs have a basic set of behaviors set by the script attached to the prefab. For individual instances, you could have additional functionality attached to the instance, if such is necessary (such as needing a level-specific key to open a door).

You might even want to bring this about by allowing prefabs to be derived and this would thusly create a variant of functionality for that new prefab (in cases where multiple doors are all opened by the same key).

Granted this is just an idea.

Just to note: A prefab is a prefabricated structure such as a model or other common level building element.

Share this post


Link to post
Share on other sites
Quote:
Original post by staticVoid2
the problem is that now the game could (possible) be implemented fully in a scripting language.

That's a problem?

Quote:
I want to know how far should you implement features of your game in C/C++ (or other) and what parts should you implement in script?

If you're using a powerful scripting language (eg, Python), there's little reason not to implement the majority of your game with it. If your architecture is Python with a C++ extension for all the graphics/sound/etc heavy lifting, it becomes very easy to write everything in Python, and if you identify performance bottlenecks in the future, push those functions or classes into C++.

The difficult part, as you seem to realize, is creating a good interface for the script. There's no simple correct answer to this, but you should try to provide enough power so that you don't have to constantly modify your C++ code when you want to add new features. The extreme (and highly useful) version of this is something like Python-Ogre, which is just a thin wrapper around OGRE and other game-related libraries, so you really could write your entire game in Python. And because you need only a few Python calls to do a lot of C++ rendering work, it's still quite fast.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this