Friday, 6 December 2013

Why scripting is hella useful (when used properly)

Scripting in game engines can be extremely useful - it allows the game to work on smaller scales that can be easily modified without having to recompile heaps of code. It allows game designers to come in and modify the things they want as well as create complex, single event scenarios. It allows for so many things (although there are some negatives, which we'll discuss towards the end) and in this blog, I will be explaining and examining what they are as well as how my group will be implementing scripting in our game.

The first thing to understand is that scripting is usually used within a component based model. A component based model means that the game is composed of game objects with various components. These components run independently of each other, and each has its own scripts and properties. These components (and game objects) are usually controlled by an entity. The entity is able to manage the each component that is under its control as well as pass messages between them.


These entities can work together to create what we call "systems." These systems, when put together, create the game engine. What's nice about this is that each system is independent of the other - which turns the engine into building blocks of code, if you will.


So where does scripting fall into play?

Script is the tool that allows the component to interact with the other objects and components. Game engines that are heavily component and script based are easier to use than those that aren't as developers can just hop in and edit the things they need to (jump speed, attack power, defense stats, etc.). The other benefit lies in the "building block" example: engine code can be pulled out while leaving the game logic behind. This allows the engine code to be used across multiple engines - which is useful for speedy iterations and prototyping.

How are we implementing this in our game?

Well, thankfully for us, Phyre Engine does everything we need. It comes with a level editor and Lua scripting - powerful tools for game creation. This allows us to import any game object we create and then add scripting components as necessary. Within Phyre, it is possible to instantiate and manipulate components via scripting as well as C++. The first thing to note is that Phyre comes with some simple, initial scripts. Scripts are integrated throughout the whole engine already with an easy to use interface, so we decided that scripts would be the main focus for our game.


Above is an example from an assignment I handed in for school. As you can see, this "boxmang" has a bunch of components, each performing its own task:
  • Animatable Component: allows the object to play animations from its animationSet (which is a group of animations for a single object)
  • boxmangCC: a character controller for the "boxmang" - this gives him the ability to activate triggers that he is linked to (this is also linked to the script below)
  • Physics Character Controller Component: gives the "boxmang" controls and physics for collision, movement, etc.
  • Quarry Component: used for triggers
Now, let's look at Phyre in a broader scale, to see how we can use this object in a game scene.


The Palette contains all of our assets, components, and custom scripts. They can be customized in here as well. The Objects box contains instances of the things from our Palette. Instantiation is as easy as dragging and dropping your selection from the Palette into your Object window.


An example of what the above Pallete/Object windows create in the scene.

A great example of scripting done right is Naughty Dog's Uncharted series. These guys have sequences referred to as "scripted-set pieces." These are the times when you'll be climbing and the ground will give way, or things will blow up - a great example is at the beginning of Uncharted 2 when you're climbing the train. 


That whole intro is a scripted-set piece. I imagine it is implemented in a way such that it uses the base framework for climbing but has triggers that activate different events such as the camera's position, what environmental animation is playing, how Drake responds to the situation and what animation to play, etc. There is also scripting for specific animations playing based on those 1 on 1 enemy fighting scenes. The scripts allow for specific kill animations to happen based on where you are, what buttons you've implemented and if there are any environmental triggers nearby. For example, Drake can stealth up behind an enemy and do a silent take-down. These take-downs are different based on where Drake is in relation to the enemy as well as what is around him.


So there you have it - scripting is a useful tool that shouldn't be overlooked. Be forewarned though - the way scripts work with your engine is the key to how well the scripts will run. While it might seem like common sense, this can lead to lots of power need to run all your scripts. This is why you should carefully consider which engine you will be using (or when making your own, how to make sure your scripts interact nicely).

No comments:

Post a Comment