Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Torque 3D Game Development Cookbook

You're reading from   Torque 3D Game Development Cookbook Over 80 practical recipes and hidden gems for getting the most out of the Torque 3D game engine

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849693547
Length 380 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
DAVID WYAND DAVID WYAND
Author Profile Icon DAVID WYAND
DAVID WYAND
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Torque 3D Game Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. TorqueScript: The Only Script You Need to Know 2. Working with Your Editors FREE CHAPTER 3. Graphical User Interface 4. Camera and Mouse Controls 5. Your Graphics Evolved 6. Make That Sound Happen 7. Game Objects 8. Multiplayer Servers 9. Importance of Networking 10. Miscellaneous Gameplay Features Index

Creating a new Datablock object


Datablock objects have static properties and are used as a common data store between game objects that derive from the GameBase class. They are defined on the server and are passed to clients (by SimObject ID only) during the initial transmission of a game level. In this recipe we'll see how to build a new Datablock object.

How to do it...

Creating a Datablock instance is straight forward. Here we will create a StaticShapeData Datablock, one of many possible Datablock classes as follows:

datablock StaticShapeData(MyShapeData)
{
   category = "Scenic";
   shapeFile = "art/shapes/rocks/rock1.dts";
   computeCRC = true;
   isInvincible = true;
};

How it works...

We use the datablock keyword when creating a new Datablock class object and always give it a unique global name. This name is used by other objects to reference this Datablock through the use of datablock property of the GameBase class.

If we happen to create two Datablock instances with the same global name but of different classes, then a Cannot Re-declare data block with a different class error is output to the console and nothing is done with the second Datablock instance. However, if the two global names and classes match, then all of the properties from the second Datablock instance are copied into the first.

There's more...

There are a number of different things to keep in mind when it comes to creating a Datablock instance. Let's take a look at them.

Creating a new Datablock object based on another Datablock object

We can base the properties of one Datablock instance on a previously created Datablock instance through the use of a copy source during the creation of the Datablock object. The process is the same as when using the new keyword. See the Creating a new SimObject instance recipe for more information on using a copy source.

Limited total number of Datablocks

The SimObject ID of a Datablock instance comes from a special pool that is reserved for the Datablock class. This ID pool only allows 1024 Datablock instances to be defined per game level. This number may be increased by changing the source code of Torque 3D. It is this special SimObject ID that is transferred between the server and client in a multiplayer game, and is used by the GameBase derived classes to reference their Datablock object on the client.

The datablock keyword should only be used on the server

Use of the datablock keyword should be limited to the server script files. Only the server keeps a track of the special Datablock ID pool, and all the Datablock objects on the client are deleted just prior to a game level being loaded.

Datablock properties should be considered static

Once a Datablock object has been created, its properties should be considered static. It is possible to modify the properties of a Datablock object at any time, just as with any other SimObject, but this should be avoided. The modified Datablock properties are not retransmitted between the server and client and will result in strange errors during game play.

See also

  • Creating a new SimObject instance

  • Creating a new internal name only SimObject instance

  • Creating a new singleton recipes

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image