Game Script Design Template

I am a web developer and I am trying to create a game. After some research really didn't find any final design patterns for games other than State Based (which is similar to what everyone does).

People talk about scripting in games, but I just could not find a good resource for this or, even better, a good example of running code.

I tested Lua and Groovy, but I lost a bit how to use these scripting languages โ€‹โ€‹integrated with the game's core code.

Any help is appreciated (books, sites, etc.)

+4
source share
2 answers

The issue in question is about games, but the same logic applies to any application that behaves differently at runtime based on user interaction. As Mark says, you can implement this in scripts that your application interprets, or create functions directly in your main application. Why do you want to do the first?

  • It makes your game fashionable; users can add features or specialize in your game.
  • Separates the platform (hardware or OS) from the game logic; this allows different teams to simultaneously work on various aspects of the game. It also makes it easy to port or update your game.
  • It separates application data (files, networks, user interface) and games (quests, graphics, sound). Applied and game creation are different skill sets; trying to do it is about as easy as trying to make a movie where you are both a director and an actor.

So, you decided that you want to create a script game; how to do it? First decide whether you want to become a director (write a game engine) or an actor (run scripts). Noctrin has posted good links for writing game engines.

If you want a game script, you would be better off choosing an existing game engine. Neverwinter Nights is a published game with a good modding community. If you need a free open source game, check out Dungeon of Despair .

I do not recommend creating a game engine, scripting language, or game logic yourself. Although possible, this is a titanic amount of work.

+4
source

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.

+5
source

Source: https://habr.com/ru/post/1334692/


All Articles