Introduction to torque engine series scripts

Source: Internet
Author: User

I have been in touch with the tgE engine for almost two years. TGE is a very good foreign game engine. Low Price (99 dollar only), support for scripts, built-in GUI Editor, particle editor, and Scenario Editor. The most critical defect is that the network part can only support more than 100 clients. Therefore, to develop multiplayer online games, you need to change the network part. However, if you want to develop a single-host or LAN game, the tgE engine is indeed a good choice. In the future, we will introduce the torque engine in several articles, including the use of scripts, editors, and engines.

Part 1: getting started with scripts
************************
1) Open the Console)

Run torquedemo.exe to enter the main interface or game, and then press ~ Activating the console is a good place for debugging programs.

2) Try the simplest command echo ()

Type echo ("Hello! "); (Note that it must be added; just like C ++) You can see hello in the console window! Do not underestimate echo (). Sometimes, In order to debug the script program, add echo () in the appropriate place to display the value of the variable, You can monitor whether the program is correct. When Echo () is used, if you want to input multiple rows of statements, you only need to input them consecutively. Torque runs the statement according to the statement, for example, $ A = 1; echo ($ ); output: 1
3) features of torque script:
A) It is out-of-the-box and out-of-the-box. B) variable type flexibility, for example, "12" is the same as 12 C) case insensitive, % A and % A are the same d) similar to C ++, each language name must use; as the end mark
4) variable. In the torque script, $ indicates the global variable, and % indicates the local variable representation. $ A indicates the global variable A (in the network, the global variable only indicates the global variable on the client, not the entire network.) % B is the local variable B (generally used in function)

Variable type: a) number 1234 (integer interger) 1.234 (floating point floation point) 1234e-3 (Scientific notation scientific notation

B) string type "ABCD" (string) 'abcd' (tagged string)
Try another interesting statement: ECHO ("1" + "2"); outputs: 3 instead of concatenating two strings. The connection is operated by @, for example: echo ("1" @ "2"); output: 12 this is the flexibility of torque script, more character connectors: @ concatenate two strings, tab and tabspc, and add a space between the two strings. nl, and add a line feed between the two strings. Note: The English letters of these operators must be uppercase. For example, echo ("ABCD" NL "cdef"); will output: ABCD cdef
Commonly used Character Color Processing:
In principle, it affects the subsequent characters until a new font color operator appears, but it only affects the characters in the current line, and does not affect the default font color.
Echo ("/c2hello! /C0hello! "); The previous hello! Red, the last hello! Normal black is displayed.

C) logical type: Like other languages, torque has only two values: true (1) False (0)

D) array (arrays) Representation: $ AA [N] One-dimensional array $ AA [M, N] multi-dimensional array $ AA [M_n] Another representation of multi-dimensional arrays, the variable name can be the same as the array name, but the value does not produce and affect: $ A = 2; $ A [0] = 3; more interestingly, in the torque script, the array can be pointed to using the following method: Next, In the above example, you try: ECHO ($ A0); the output is the value of $ A [0]. Likewise, if you want to output $ A [], you can use the following method: ECHO ($ a0_0); again, torque scripts are quite flexible.
D) vector (vectors): The format is as follows: "1.0 1.0 1.0 1.0" vector is a widely used variable type in the engine, sound Effects and so on have corresponding applications.
5) operator, which is similar to C ++

6) The control statement is basically the same as that of C ++.

7) Function
Function module name ([parameter 0],..., [parameter n])
{
Statement;
[Return value;] Optional
}
8) define an object and introduce some basic knowledge. Here we start to enter the syntax unique to torque. In torque, all projects are "objects", and all objects in the game can be accessed, such as characters, cars, and objects in scenes. All objects can be accessed using scripts, and the attributes of objects are defined in the engine.

Let's look at the code in a script (Excerpted from server/scripts/player. CS)

Datablock playerdata (playerbody)
{
Renderfirstperson = false;
Emap = true;

Classname = armor;
Shapefile = "~ /Data/shapes/player. DTS ";
Cameramaxdist = 3;
Computecrc = true;

Canobserve = true;
CATEGORY Category = "clients ";

Cameradefaultfov = 90.0;
Cameraminfov = 5.0;
Cameramaxfov = 120.0;

Debrisshapename = "~ /Data/shapes/player/debris_player.dts ";
Debris = playerdebris;

...
};

Datablock defines the attributes of an object.

This section defines the attributes of a gamer's character, including the Perspective definition, 3D file (DTS), and so on,

Load it in server/scripts/game. CS:
...
Exec ("./crossbow. cs ");
Exec ("./player. cs"); // load the object defined in player. CS
Exec ("./chimneyfire. cs ");
Exec ("./aiplayer. cs ");

...

Loading is only a pre-loaded memory and is not actually created. Now let's take a look at where the character player is created.

In game. CS, you can find the relevant functional modules:

Function gameconnection: createplayer (% This, % spawnpoint)
{
If (% This. Player> 0 ){
// The client shocould not have a player currently
// Assigned. assigning a new one cocould result in
// A player ghost.
Error ("attempting to create an Angus ghost! ");
}

// Create the Player Object is where the player object is created, and return the name handle to % player.
% Player = new player (){
Datablock = playerbody;
Client = % this;
};
Missioncleanup. Add (% player); // Add to the scene

// Player setup...
% Player. settransform (% spawnpoint); // set the random occurrence location, which is defined in the scenario editor and generates random points in the function pickspawnpoint () function.
% Player. setshapename (% This. Name );

// Starting Equipment
% Player. setinventory (crossbow, 1); // initial weapon settings
% Player. setinventory (crossbowammo, 10); // configure the ammunition in the initial state.
% Player. mountimage (crossbowimage, 0); // set the assembly point 0 of the weapon in the character to mount0, 1 to mount1, and so on.

// Update the camera to start with the player
% This. Camera. settransform (% player. geteyetransform (); // sets the angle of view mode.

// Give the client control of the player // assign the control to the Player Object
% This. Player = % player;
% This. setcontrolobject (% player );
}

To sum up, the method for creating object objcect is as follows:

% Ver = new object type (name) % ver is the returned handle, an integer, unique value of the client in the game, equivalent to the Object ID.
{
Datablock = datablock definition; // This is required. datablock can be customized or contained in torque. For details, see the datablock appendix of torque.

Built-in property 1 = initialization value 1; // optional. If this parameter is not selected, the default value is used.
Built-in property 2 = initialization value 2;

...

Custom attribute 1 = initialization value 1; // optional. The custom attribute can only be applied in the script and does not affect the built-in attributes of the engine.
Custom property 2 = initialization value 2;

...

}; // This; not required.
Note: The returned handle has a unique value on the client, but different IDs in the network. Therefore, an object has two IDs: local ID, network ID, and network ID.
The unique ID number in the game network. When programming online games, you should note that the method for obtaining the network ID will be explained later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.