Jump to content
  • Advertisement
Sign in to follow this  
Inuyashakagome16

Using Multiple Languages In One Project

This topic is 2160 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been wondering for a while, Why would developers use multiple languages in a project?
I've heard that some will use LUA with C++, why is this?
Same goes for C++ and python. Mind you I've never found the "Need" to do that hence why I'm asking.

What could a developer gain from doing so?

And would there be any cons to it?

Share this post


Link to post
Share on other sites
Advertisement
In these contexts languages like Lua and Python are mostly used as scripting languages inside that C++ environment
The benefit of this is that scripts do not have to be compiled and are interpreted at runtime, this allows for on the fly editing of code without having to recompile every time you change something. This is a major advantage for large projects since compile times can become long.

The downside is of course that these scripting languages probably won't run as fast as your native code does, so time critical code would still need to be written in the native language.

EDIT:

Damn, ninja'd by Hodgman Edited by Radikalizm

Share this post


Link to post
Share on other sites

Because C++ is not a "productivity language", it's a "systems language".
You can only trust expert programmers to write good C++ code, because C++ makes it way too easy to write code that appears to work, but is actually corrupting memory, leaking memory, etc, etc...
When using a more modern language, like C#, Python, Lua, et al, you can implement more features in less time, using less code, and with less bugs. Many of these languages also have great support for dynamic programming -- so for example, if your game "crashes" on a line of bad code, you can fix that line of code while the game is still running, hit your "reload code" button, and the game continues on without crashing! Same goes for tweaking/iterating features -- you can tweak your pathfinding code while the game is running, and see the results of your changes immediately, without having to quit/recompile/reload your game.

The usual practice is to have your expert systems programmers write the low-level engine functionality in C/C++ (a systems language), and the game programmers write the game in Lua/Python/C#/etc (a productivity/"scripting" language).

So the pros are: less development time (== less money required to make the game).
And the cons are: more memory usage and slower performance in the game code (which is why the engine is still usually written by C++ experts).

That does make sense. Honestly, I've only been learning C++ as a single language to use that to make games instead of taking advantage of using other languages. But from what you say there can be performance issues. But as a one man team, it seems like I would rather have performance issues then write code forever on a small project.

But, lets say that I have a C++ engine I want to use; I write the base functionality for the game (sprites, movement, etc) I import that code I wrote into the other project/IDE, say VS or Code::Blocks and use C# for the main sections of the game, would C# be what would determine the layout of a world? and the occurrence of enemies etc. I'm just trying to put this into something I can fully understand. I know both C++ and C# to an extent, and if I can just use C# more than C++ I'll be okay with that. :P

C++ = Base of game, basic functionily

C# = How each of those functions are used and where?



In these contexts languages like Lua and Python are mostly used as scripting languages inside that C++ environment
The benefit of this is that scripts do not have to be compiled and are interpreted at runtime, this allows for on the fly editing of code without having to recompile every time you change something. This is a major advantage for large projects since compile times can become long.

The downside is of course that these scripting languages probably won't run as fast as your native code does, so time critical code would still need to be written in the native language.

EDIT:

Damn, ninja'd by Hodgman

lol Ninja'd. I see what you're saying though. :o That does make sense.

Share this post


Link to post
Share on other sites
I'd like to add, as a general rule don't mix languages unless for the popular combinations such as those that have already been brought up above. I've dabbled for 6 months in C++/CLI and converting array's of bytes trough another language just to get it's data was a very tedious process. I literally spent one month making an interface DLL that would be compiled in /clr. My other choice was creating a servery with some TCP message forwarding the results to the other application. Edited by DZee

Share this post


Link to post
Share on other sites
I read about this all the time but never see it in action. Would someone be so kind to post some code snippets, or books on this topic

Thank you. Edited by cyberolla

Share this post


Link to post
Share on other sites
It was sort of hit on already, but I'm curious if using scripting language as a one-man team would be helpful. I use Java for what I'm doing now, but if I can make my life easier by dabbling in Python a bit, that would be great.

Any one-man dev teams here with experience in using a scripting language with their games?

Share this post


Link to post
Share on other sites
Different languages have different properties, advantages and disadvantages, the goal is to use the right tool for the right job, if your game is rather small and you are most familiar with C++ and already have an engine up and running, don't try to bring in a second language, unless you need to or unless you are just aiming at a learning experience rather than a finished product.

Another combination that wasn't mentioned comes in when games use databases, you'll have to integrate SQL.

Lets say you are aiming at a learning experience and go back to the script purpose usage of light languages (C#, LUA, python, AS) combined with C++ for performance.
What you want with a script language is a way to change the stuff that is most likely to change by design quickly and if possible on the fly, without having to close the app and compile and so on.

Take collision detection for instance, finding out if two boxes are overlapping is a rather rigid algorithm, you'll write it once and as long as it works ok you'll probably won't touch it again except perhaps to optimize some of the math. What you do when the collision happens on the other hand, is a design decision, for instance, object Bullet collided with object Avatar, C++ will tell you that happened, then you go to script, lets suppose its LUA and call the function AvatarGotHit, there you will take out HP points from him, the game designer then wants to add a shield, that protects from damage, then he wants the shield to be useless if the avatar was jumping at that moment....

You get the idea, the most efficient use of a scripting language is to use it to interpret a certain event that can be highly circumstantial and decide what to do about it, the actual doing of that will usually be best done back on C++
It is also, as has been mentioned, very useful to the balancing process, you have the "Jump" function in C++, how high the player can jump would be a number to be read from the Scripting language, that way the game designer himself can take the player, jump, change the jump height and try again until he likes it without bothering a programmer once.

Share this post


Link to post
Share on other sites
For instance, Lua is useful in the gamedev context: http://www.altdevblogaday.com/2012/05/05/embracing-dynamism/

See also:
http://polyglotprogramming.com/
http://www.infoq.com/presentations/Polyglot-Programming-The-Power-of-Hybridization
http://blog.enfranchisedmind.com/posts/not-too-stupid-for-polyglotism/
http://msdn.microsoft.com/en-us/magazine/dd483224.aspx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!