What are Scripting languages used for in games?

So i like to learn by making games and recently found out about scripting languages and how they can help development but i’m not sure what scripting languages do for video games but a buddy of mine said they can be used for logic/UI/HUD designing.

I use java to hard code my games logic and XML to store data.

Can anyone explain what scripting languages are and what they do to help development?

and what scripting languages go along with java and are good/easy to learn?

Scripting languages can be used for a variety of things. For example, let’s say you’re making an RPG and need this character in a certain cutscene to move around this house, stop, and talk to you. Instead of hardcoding it in, you can run a script file that does the same thing. What I use them for is for the content part of the game, ie: this one part of the story but not the internal code that renders text.

A good scripting language to learn is Lua. A simple wrapper found with a quick google search brings up LuaJ.

Another example is Behavior trees. Traditional programming languages are pretty bad for implementing complex behaviors (most people would probably say AIs here).

Java has a very good built-in scripting language in the form of JavaScript, which is arguably a much better fit than Lua as it’s all built-in.

One reason you’d use scripting languages is to give non-developers (eg. modders, fans, “artists”) access to certain aspects of your game engine without them having to become familiar with the build process - scripts are generally all about “just drop a source file in here and it will just work”. So no compilation, few security risks, considerably simplified skill set, etc.

Cas :slight_smile:

I once used Lua, but that was for a C++ project. For java, it doesn’t fit so well.

Indeed, Lua is the solution to a problem that C++ programmers have, not really one that Java developers have.

(There’s a school of thought that also says that Java is actually simple enough to use as a scripting language itself)

Cas :slight_smile:

Actually, I like that idea better than Java script. It’s kind of cool to compile class files during runtime and load the bytecode. A field where interpreted languages can excel.

And if you’re on desktop…there’s all kinds of goodness with jre-8 features.

so since Lua would be a good solution for c++

Whats a good scripting language for java? I looked up other languages that run in the JVM and saw 4 Scripting languages that plays well with java and they are Python, Ruby, Scala, and Groovy.

Depends. What do you really need? The suggestion of java as the scripting language is quite good if java does what you need.

i guess i’d need it for logic/behavior/UI designing

I have to disagree. In what sense is a scripting language different to a traditional language? Why have these glaring faults in traditional languages not been fixed?

In my opinion, scripting languages are only interesting if you want to treat certain aspects of game logic like an asset file, at the expense of performance.

This is an indication, that you are trying to find a solution to a problem you don’t have… So my humble advice would be to stick to making a game until you realize you can’t continue without a scripting language (which I doubt will ever occur)…

Well one could implement behavior trees in any language that expands expressions…but I really meant imperative languages. Attempting to write BTs in an imperative language would be horrible.

Traditional languages for general purpose programming are loaded with glaring faults…but that’s a different story. I spend a high percentage of my time writing in DSLs because there isn’t a GP language that covers a particular need.

Then it may be too late and he may need to refactor everything. Don’t get me wrong, you are essentially right, but I’d try to think ahead of the problem.

It’s not that i have a problem at the moment, but more of asking for advice on scripting languages and how one would use them in their game and which would be best to use/learn.

You need to anyway. Anybody ever created a nontrival software, had found that thinking ahead of a problem most of the time does not work, simply because there is so much that can go wrong, especially with complex systems.

So the most successful strategy is to keep things simple until you are forced to add another layer of complexity. Then design this layer taken into account the use-case you currently know of and refactor. You’ll find that you will do this more than once.

Trying to fight future problems with complexity will most likely fail. The worst complexity you’ll find in a system is the one you introduced to make something look simple and hide complexity. This not only introduce invisible complexity, but also inflexibility, because you have no clear vision of the control flow where you can handle stuff, you didn’t think of while designing your abstraction.

A scripting layer is something way more complex and involves more work that you typically think beforehand:

  • You need to define an API that is public to your scripting and provides access to the needed subsystems
  • You need to document this well, because you might loose IDE support for code-completion
  • You might (partly) loose debugebility, since you cant step through scripts or over script/engine boundaries easily
  • You might (partly) loose refactoring, since IDEs might not recognize your scripts calling refactored classes and methods
  • You need to make your engine thread-safe, since scripts usually run in threads and might access you engine objects arbitrary
  • You need to find a way to organize/limit those threads with pooling and execution schedules, since you don’t want a thread per entity for larger games
  • You need to handle script contexts and their garbage collection to not introduce memory leaks
  • etc.

Depending on the language choosen and the use-case implemented, not all of the above might hold, but on the other hand you might get a lot more of those in other cases, so you get the idea…

All in all I would go for just using java and maybe some continuations framework to be able to write non-stepped behaviours.

The only purpose of using a scripting language in Java that I can see is, if you want to outsource large parts of your game logic (like quest logic) to be done by somebody else who can’t be bothered or shouldn’t have to compile the game all the time while working on his part. Like an artist working on textures for example.
Personally, I never really understood the need for a scripting language for anything other than that. In my RPG, I have XML descriptions for dialogs and quests. They support dynamic branching and a basic set of conditions via some specific attributes. That way, you can still have logic errors in your quests but it’s far easier to comprehend than some dedicated script IMHO.

Speaking of which,

https://github.com/praxis-live/compiler-javac7 - forked version of javac
https://github.com/praxis-live/compiler-janino-commons - forked version of Janino to work with above compiler, so allowing class / method / expression bodies as well as classes.

Incidentally, this is how Praxis LIVE handles live coding. In fact, Praxis LIVE projects are saved as fragments of class body code in source format, interspersed with connection data and properties. Java is a great scripting language!

OP. Since you need to ask why you need then you’re answering your own question. You don’t. A better place to look would be data driven design which you can get a ton of mileage out of.