Sign in to follow this  
Photonman

Scripting

Recommended Posts

Ok, I've tinkered with Python before, but I've been hearing a lot about integrating scripting languages with, say, C++, recently, and I'm just not getting it. What tasks would you need a script to do that a program is incapable of doing? Most scripting languages are fairly fully-featured languages capable of writing entire programs on the same scale as any other PL, so what's the big diff? Also, How do you interface the script and the application? Is it like using XML documents to load values, but more complex (funtions and the like)?

Share this post


Link to post
Share on other sites
Integrating scripting languages isn't about capabilities; it's about productivity.

Why is writing code in Python more productive than in C++? Same reason C++ is more productive than assembler - because it's more abstract. You can do more work with less code, and the work you do is safer and more reliable. (Think Python strings/C++ std::string versus directly writing bytes into memory.) Embedding languages is typically done for two reasons: to make the original programming team more productive, and/or to let people outside the original team extend the program easily.

Games are some of the biggest users of scripting languages for productivity. There is a sort of unwritten rule in programming that says always write code at the highest possible level of abstraction. Embedded languages let us write more abstract code easily. If you need to program a huge battle scene between thousands of warriors, would you prefer to do it in assembler or Python?

Extensibility is big in the office software realm. If you've ever used macros for something like Word or Excel you'll be familiar with this concept. Basically the idea is to give users a simple and easy-to-learn language (like Python or Basic) so they can add on to the core program without needing the original source code, or knowledge of the original language.


The techniques behind integration depend a lot on the two languages being merged. In Python's case you can actually set up C++ classes to become native Python objects, and have C++ code talk to Python objects as if they were C++ objects. A well-embedded Python system is actually basically the same as being able to interchange C++ and Python code at will (more or less). Other language combinations range from similar levels of power to more separated systems where the two languages can only communicate via a defined set of API functions. Typically the host language (e.g. C++) will get a way to send data to the embedded language, and call functions implemented in that language.

You can read more about how Python embedding works here.

Share this post


Link to post
Share on other sites
There was a thread on this a while back here (and indeed there are many others on this topic). As to why you should use a scripting language I fully agree with ApochPiQ. Also consider this (quoting myself from the thread I linked to above).

Quote:
If you wanted to you could write an program that converts your data files to header files (i.e. store all the data in predefined constant arrays) and then just include all the header files instead of writing stuff that loads your data from files. Needless to say this is a bad idea, so why do the same for your game logic?


Scripting language can be very helpful in game development, I suggest taking a look at a few.

Share this post


Link to post
Share on other sites
Yeah a really good reason is that you can expand your game without having to recompile/modify your engine. For big projects a goal should be to be able to add stuff to the game without having to touch the engine at all ;).

Share this post


Link to post
Share on other sites
So basically, one of the ideas behind it is to be able to write an engine and, through modifying the scripts be able to rewrite functions without recompiling the game? If so, how do the APIs handle interpreting function code from the script lang into the engine lang?

Share this post


Link to post
Share on other sites
It's not a matter of rewriting functions so much as building new systems out of the building blocks that the engine code gives you. Really it's analogous to using the Windows API functions to build Windows programs; you're not rewriting Windows, you're using the features it offers to spare yourself a lot of work (drawing stuff on the screen, messing with the mouse, etc.).

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