There are many different scripting languages, but one of the main scripting languages being used recently by a lot of developers is LUA.
Some features of LUA are:
- Compiled to bytecode
- Hot swapping
- Highly embeddable
- Highly customizable
- Dynamic typing
Some Pros of LUA are:
- Iteration Times
- Expressivity
- Designer-accessibility
Some Cons of LUA are:
- Performance
- Designer-accessibility
Scripts such as LUA give designers an easier time to balance or change attributes to the game itself without touch the code which really helps with the developing process. At the same time they can hinder or ruin the programmer's work by using the scripts. These scripts are essentially the pillars of the Engine itself and their components can be implemented in C++ or LUA. The scripts is basically a special sauce or the thing that glues everything together.
Typically scripts are used for data and what scripts should do are to save out the state of the scripts, drive the system with data and define the structure for both. LUA can define structures for engine-allocated data blocks, and the engine controls the lifetime of these blocks. LUA reads and write to the blocks but it is never allowed to allocate it's own dynamic memory. This essentially give the user a fluid design environment and it allows for the developers to put all their hacks, because every game has their own unique hacks or a "different" way to implement a feature.
Generally what you want your scripts to deal with are:
- Health/Damage/Death/Stats
- Weapons/Equipment/Items/Abilities
- Artificial Intelligence and Behaviours
- Heads Up Display/User Interface/Menus
- Missions/Levels/Objectives(Quests)
The difference between C++ and scripts is that C++ code is technology that can be used for other things such as for another game, it is a framework for your games. Scripts are the stuff the make the game unique from all the other games.
Scripts are also called DSLs or Domain Specific Languages which is a language designed to be highly adept at solving a specific class of problems these can include LUA, Python, Lisp, etc. DSLs are used for AI because firstly, for code cleanliness and the effects of mapping code directly into the problem, secondly, it eliminates low-level concerns that do not apply to the specific problem and finally, it speeds up productivity and removes excess overhead that are not related to the problem.
The benefits for avoiding low level issues is that there is no manual memory management in code, no complex syntax and no complications such as undefined behaviour. It doesn't require a high level of knowledge in programming and it reduces the probability of severe bugs to occur in the code. DSLs should be simple that even the user with basic programming knowledge can use it. The goal of using DSLs is to place all data and logic into the DSL and out of the core engine code.
The first things to do when created a DSL is to:
- Identify the core problems the AI must solve
- Select algorithms and solution for each problem
- Break down the solutions into discrete chunks
- Implement DSL concepts for each chunk
When implementing DSLs it is ideally better to keep syntax simple and clean, deploy simple code for parsing, map syntax elements to constants or classes and excute the DSL code in some fashion. The syntax should be able to parse easily, everything should be easy to understand and must make sense and use specific operations rather than general ones.
When executing DSLs build a miniature interpreter, embed the DSL in C++, Lua, etc. or compile to another language.
Everyone can benefit from the use of DSLs. Programmers have a safer environment, Junior team members can do critical AI work, Designers can write logic directly, code reviewers will be less burdened and QA testing will be optimal.