There are various ways to support scripting in games; This is a sliding scale.
On the one hand, you can have almost everything that works using the scripting language, so you define all your data, logic, etc. using scripts, and just have some basic kernel functions in C / C ++. In this scheme, almost everything on the C / C ++ * side is only on that side of the gap to make it efficient enough, or because it is already written in this language and will be expensive to redefine.
On the other hand, you can have most of your game code and data defined in C / C ++ and implement bindings and / or callbacks to allow some settings through scripts. Bindings (e.g. LuaBind ) allow your scripts to receive and set call values โโ/ functions that are not defined in the script code, but on the C / C ++ side. Callbacks allow scripts to listen on to trigger game events; .eg you can have a script that gets called when an entity is about to do damage. Then you can customize / expand your game logic with scripts.
The Game Engine Architecture book does a good job of explaining the possibilities, although it doesn't include sample code or anything like that.
how scripting depends heavily on which implementation style and which kernel and scripting languages โโyou choose. If you want something more specific, try using some language choices (like C ++ and Lua), and then track down some tutorials like this one .
why it depends on the approach, but usually it separates the functionality / behavior / data of the game process from the guts of your game engine. This simplifies the change, since you can reload scripts at runtime without rebuilding the rest of the project. A well-executed scripting system also makes it easier for people to participate or modify / extend the game without disturbing the programmer.
Specific example:
You might want to create functionality that tells the player how much damage they caused during the round.
If you do this on the C ++ / core side, this means that the programmer must download very specific code in order to serve a very specific function, rebuilding the entire project and deploying the new version. Then they check with the designer that everything is grand. If this is not the case, they should recode and rebuild, undermining a lot of time.
With a well-designed scripting system, this is just the case of dropping round_damage.lua script into the scripts folder. The script automatically rises and activates when the game starts, and each time the player takes damage, the "OnDamageReceived" handler fires. When the round completes, the OnRoundEnded callback starts and the script displays the message.
A rich set of hooks is provided, the script can do all this without the help of a programmer. If they make a mistake or want to try something else, the script can immediately reload the script without shutting down the game.
* Notice, I say C / C ++ for the core material of the kernel, because it is a common choice, but it can be any language fast enough for your purposes.