Compare Guide

Scripting vs Engine Programming

As mentioned above, TorqueScript is comprised of the core C objects needed to make your game. For example, you will use the PlayerData structure to create player objects for your game. This structure was written in C :

C PlayerData Code:

struct PlayerData: public ShapeBaseData {
typedef ShapeBaseData Parent;
bool renderFirstPerson; // Render the player shape in first person
mass = 9.0f; // from ShapeBase
drag = 0.3f; // from ShapeBase
density = 1.1f; // from ShapeBase

Instead of having to go into C and create new PlayerData objects or edit certain fields (such as mass), PlayerData was exposed to TorqueScript:

Example TorqueScript PlayerData Code:

datablock PlayerData(DefaultPlayerData)
renderFirstPerson = true;
className = Armor;
shapeFile = "art/shapes/actors/gideon/base.dts";
mass = 100;
drag = 1.3;
maxdrag = 0.4;

// Allowable Inventory Items
maxInv[Pistol] = 1;
maxInv[PistolAmmo] = 50;

If you want to change the name of the object, the mass, the inventory, or anything else, just open the script, make the change, and save the file. When you run your game, the changes immediately take affect. Of course, for this example you could have used the Datablock Editor, but you should get the point. TorqueScript is the first place you should go to write your game play code.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License