Torque engine syntax

Source: Internet
Author: User
1) Open the Console)

Run torquedemo.exe to enter the main interface or game, and then press ~ Key (shift is not required, it is actually a key) activated
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!
Let's look at echo (). Sometimes, to debug the script program, add echo () in a proper place to display the value of the variable,
Check 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 will execute the statement according;
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, such as "12" and 12.
C) Case sensitivity. % A is the same as %.
D) similar to C ++, each language name must start;
4) variables
In the torque script, $ indicates a global variable, and % indicates a local variable.
Representation: $ A is the global variable A (in the network, the global variable only indicates the global variable in the client, not the whole network)
% B is the local variable B (generally used in function)
Variable type:
A) digital
1234 (integer interger)
1.234 (floating point)
1234e-3 (Scientific notation scientific Notation)
0xc001 (hexadecimal)
B) balanced type
"ABCD" (string)
'Abcd' (tagged string)
You can try it on the console:
Echo ("ABCD ");
Echo ('abcd'); what is the difference
Try another interesting statement:
Echo ("1" + "2 ");
Will output: 3 instead of connecting two strings. The connection is operated by @, for example:
Echo ("1" @ "2 ");
Output: 12
This is the flexibility of torque script,
More character connectors:
@ Connect two strings
Tab: adds a TAB between two strings.
Adds a space between two SPC strings.
NL adds a new line between two strings)
Note: The English letters of these operators must be uppercase.
For example, echo ("ABCD" NL "cdef ");
Output:
ABCD
Cdef
Character formatting:
/N (newline) New Line
/R (carriage return) carriage return
/T (Tab)
/C0. ../C9 (colorize subsequent text) font color
/Cr (reset to default color) returns to default color
/CP (push current color on color stack) to set the current color to the color stack unknown usage method
/CO (pop color from color stack) unknown usage of color from color Stack
/Xhh (two digit Hex Value ASCII code ..
// (Backslash) Annotation
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! ");
Previous hello! Red, the last hello! Normal black is displayed.
 C) logic type
Like other languages, torque has only two values.
True (1)
False (0)
D) array (arrays) Notation:
$ AA [N] One-dimensional array
$ AA [M, N] multi-dimensional array
$ AA [M_n] Another representation of multi-dimensional arrays
The variable name and array name can be the same, but the value does not produce or affect:
$ A = 2;
$ A [0] = 3;
Try again
Echo ($ );
Echo ($ A [0]);
The output is the values represented by each other.
More interestingly, in the torque script, Arrays can be pointed to using the following method:
Next, let's try:
Echo ($ A0 );
The output is the value of $ A [0]. Similarly, if you want to output $ A [], you can use the following method:
Echo ($ a0_0 );
Once again, torque scripts are quite flexible.
E) vector (vectors)
Format: "1.0 1.0 1.0 1.0"
Vector is a widely used variable type in engines. It is applicable to 3D coordinates, power, particles, and sound effects.

5) Operators

This is very similar to C ++, so we will not spend any space on the presentation. See the Script Programming Guide.
For example, the usage of a ++ a -- is the same as that of C ++.
String comparison operation:
$ = Equal
! $ = Not equal
For example, echo ("ABC" $ = "ABC ");
Output 1
Echo ("ABC "! $ = "CDE ");
Output 1

 

6) control statement

Similar to C ++
A) if-then-else judgment statement
If (expression)
{
Statement 1;
} Else
{
Statement 2;
}
B) Switch
Switch (expression)
{
Case value 1:
Statement 1;
Break;
Case value 2:
Statement 2;
Break;
...
Case value n:
Statement N;
Break;
Default:
The statement is executed by default;
};
Note break; required
C) while loop statement
While (expression)
{
Statement;
}

7) Function


Similar to C ++, the definition method
Function module name ([parameter 0],..., [parameter n])
{
Statement;
[Return value;] Optional
}

8) object definition objects

I introduced some basic knowledge and started 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.