Thursday, 21 November 2013

Scripting

The first time I even heard about scripting I thought, "Is that like more code that we will have to memorize or something?" I was thinking a real script that you would memorize before perform on stage or something. Clearly I was thinking way outside of what it initially was. Scripting turned out to be much more interesting than that.

What is scripting?

A scripting language can be defined as a programming language whose primary purpose is to permit users to control and customize the behaviour of a software application. In scripting language you can generally define a game logic in a separate file completely different from the used programming language in your game. Scripting allows for flexibility in engine code. You can literally include many game-specific things like levels camera control, cut-scenes, and AI behaviours into a scripting language. Not to mention that it lessens the amount of work a programmer has because a chunk of the game logic is designed by level designers. This way the engine core doesn't seem that complex anymore. Well, to me it still is, but scripting lets you see programming in a much simpler way.

Interpreted Scripts

Interpreted scripting language is a type of ASCII text file that executes instructions without compiling a program into machine-language instructions. The interpreter reads the file line by line and parses, interprets, and executes each line on the fly. Examples include PERL, Ruby, and Python.

Compiled Scripts

Compiled scripts is a compiler that translates our code into machine code. This is how we get bytecode. Bytecode is a type of instruction that the interpreter can understand. C++ and C are examples of compiled scripts because they both need a a compiler that creates the bytecode. 

Video

In this class we watched a video to learn more about scripting and how it is used in games. We looked at the video game Flirting with the Dark Side. Scripting pros include: iteration time, expressiveness, and designer-accessibility. Scripting cons include: performance and designer-accessibility. More or less scripting is the main aspect in game engine design. It is primarily the glue that brings everything together. A script is the pillar of the engine. The main production goal was to use a scripting language called Lua, which can be used to create first-class systems from the ground up.



Lua uses very simple syntax and is stack-based in which you can push and pop values. This is why the creators of Flirting with the Dark Side had three parts: component scripts, system scripts, and data. They had these component soups and system soups which contained animations, AI behaviours, physics, and so on were organized in a list or a stack. However, you need 'glue' code in C++ in order to call functions in Lua. This is as simple as it gets in programming.




Advantages of Scripting

Scripting are a relatively easy language to learn and use in your game engine. So in retrospect, it was good place for my programming skills to grow. Since I am an artist, my programming skills are in need of improvement and I really wanted to contribute to our studio game this semester in programming. So when my group members asked me if I wanted to script, I was so excited. Scripting also makes the game engine less complex and development of certain attributes in the game are made much faster. On a further note you can concentrate more on the game design, art, and tweaks that make a game look amazing and epic.

My experience with Scripting

So for our GDW game, I was assigned to script particle systems in Ogre. I have never scripted before so this was truly a cool and exciting time for me. First off, I did my research on a particular website called http://www.ogre3d.org/tikiwiki/tiki-index.php?page=-particle. This website helped me a lot since I was able to see a few examples as to how to format my script and add extra attributes as well. Here is the .particle and file for the smoke script I did.

particle_system Smoke
{
material Smoke1Mat
particle_width 3
particle_height 3
cull_each false
quota 500 //Max particles at once
billboard_type point

emitter Point
{
angle 23
emission_rate 100
        time_to_live    1.4
depth 20
position 0 0 0
        direction       0 1 0
        velocity_min    1.5
        velocity_max    12
        colour 0.0 0.0 0.0 0.1

}

    affector Scaler
    {
        rate 1.1
    }

affector ColourFader
    {
        alpha -0.04
    }

affector LinearForce
{
force_vector 0 -0.2 0
}

affector Rotator
{
rotation_range_start        10
        rotation_range_end          360
        rotation_speed_range_start     -5
        rotation_speed_range_end       10
}

}

The outcome of this smoke particle made me so happy. It looks so real. I was so excited to show my studio members the next day. They were impressed and I was assigned to do all of the particles that will be used in our game. The game is going to be about war so there will be many particle effects flying around the game such as fire, debris blown by the wind, explosions, and the list goes on and on. We have even discussed using particles in the main menu just to make it look more pretty. All in all, scripting has allowed me to finally contribute the few programming skills I have. It feels good to be an artist/script programmer.

Conclusion

Scripting is a light-weight language that is interpreted in other high performance languages like C++. It allows game developers to incorporate game-specific items and encourages game design customization to make your game more unique and controllable.


No comments:

Post a Comment