Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are some games which allow the player to write/create scripts in-game, for example: Space engineers or Psi.

I want to use something similar to either one,but I've had a hard time finding information so my question is:

There is a branch of programming that covers the ability of a software once compiled to run new code created by the user?

By branch of programming I mean something like PTG (Procedural Terrain Generation).

To avoid the 'too broad of a question' or 'opinion based', let me clearly state that I'm not looking for guides or places to learn, I want the name or definition (if one exists) of the technology involved.

share|improve this question
6  
Well, probably "Writing interpreters"? – MatthewRock 9 hours ago
2  
I answered a similar question recently, discussing "Virtual Machine" as the term for the system that runs the user code, and also referencing the Game Programming Patterns article on the Bytecode Pattern as a means of implementing this faster than a conventional interpreter. – DMGregory 8 hours ago
2  
It's usually called "scripting". You'll find plenty of materials on how to implement scripting in a game, as well as plenty of (variously) open source sample and real code. In broader scope, there's the whole field of compiler programming (which includes lexing, parsing, compiling, linking, interpreting...). In the broadest scope (not necessarily useful), this entails pretty much any user interaction your application has - a scripting engine is really just a much more complex way to select from a menu. – Luaan 7 hours ago
    
A Python program can host Python scripts. That's called metaprogramming. Most interpreted languages have that. – user6245072 7 hours ago
    
"There is a branch of programming that covers the ability of a software once compiled to run new code created by the user?" - yes, it's the same branch that allows Python, or Lua, or Java, or C, once compiled, to run new code created by the user. (C is not actually something you can compile, but it's irrelevant for this comment) – immibis 2 hours ago

Scripts written in scripting / embedded / interpreted languages such as "Lua", "Lisp" or "AngelScript" (more here) can be updated during the game [*] and then are interpreted (= executed) on the fly.

You can bind elements from those scripts to your native compiled coding (C++, etc.) so that the scripts can then execute logic from your application. E. g. a specific command that the user can put in the script, as a result moves the in-game character by a given distance in the game world.

Some relevant linked questions:


[*] either by the user as part of the game play or also by devs for fast iteration/testing without restarting the application

share|improve this answer
9  
I would be careful when calling something "interpreted language". At best it is very disputable term. – wondra 9 hours ago
1  
Computercraft (minecraft mod) uses LUA as a scripting language to program tasks within the game. – Tikeb 9 hours ago
    
I'd give you a down vote if I could (not enough rep over here) for "interpreted languages". Try to find a (seriously used) lisp implementation that's not compiled... Whether interpreted or compiled has (basically) nothing to do with the language. (I mean there are C interpreters. C Carl!) – Daniel Jour 8 hours ago
3  
I don't really understand the fuss. Lisp can be both interpreted and compiled. We aren't here to disucss how to classify the languages and whether interpreted is a good clasisfication; we're telling OP who is unaware of this fact that language doesn't need to be compiled, but can be interpreted - and we give some languages as an example. Is Lisp interpreted? Yes. Is it compiled? Also yes! But that's outside of the scope. The answer might be inaccurate with wording, but it's fine for the purpose; it pushes OP in the right direction, and that's what counts. Here, take my +1. – MatthewRock 8 hours ago
3  
@Tikeb Please don't call it LUA. It's not an acronym .-. – user6245072 7 hours ago

Embedded language is the proper technical term. In practice, languages which are used inside other applications (such as games) are often referred to as scripting or even interpreted languages, although they should not necessarily be interpreted or used for automating routine tasks. Googling "scripting languages for games" would probably yield more useful results than searching for "embedded languages".

share|improve this answer

You are looking for a way to change the code into some actions. This is precisely what interpreters are doing.

Take a look at Python. You run it, and bam! You land in REPL(Read Eval Print Loop).

You define a function "hello" which prints "Hello, world". And there you have it!

Notice that you didn't compile anything; interpreter did some magic to create function on the fly (during the runtime) and now you are able to call it.

The same applies to games. Instead of having a REPL, you have a game with REPL module. The game probably starts the REPL and then runs everything else in this REPL, so you have access to the data and can actively modify it.

If you are working with huge languages like C++, they tend to be less dynamic and probably compiled. You want some easier. You either create your own language, or use some existing(like CoffeScript, Squirrel, Lua, Scheme, ...)

These are often called scripting languages, since you use them to write scripts that are built upon the game engine developed in some other language(e.g. C++).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.