Author Topic: [TUT] Scripting - Section 1  (Read 974 times)

These guides are coming out as I make them. Later I will finish part 1 and keep going to different parts.

What is scripting? Scripting is a way to modify the way the game works, make add-ons, and to go through advanced processes. What are some examples?

Return To Blockland - A complex add-on which features use of an IRC, an in-game forum browser, an online server browser, and a preference system. RTB also includes an extensive administrative system.

ID List 5.0 - On my side, by joining a server, IDs are collected and sent to a web server to be added to a database.
(this is all I could think of for the moment)

What is Torque? Torque(script) is the language that Blockland uses. Blockland uses the Torque Gaming Engine(TGE). TS is the scripting language to use with Blockland.


First script
There are a few things you need to know.

The console is a way to quickly short scripts. In Blockland, you basically have two consoles under a normal game(as compared to dedicated servers).

You have a console that runs when Blockland first starts, and if you're not running a dedicated server, you have the game window console. The game window console can be accessed by pressing "~", next to the "1" key.

The plain and black(DOS-like) console does not allow you to paste/copy like the in-game console does.

An scripting entrance to either of these consoles will echo back, with a success or failure message.

A function is a way to execute a series of instructions without being executed immediately.

Code: (TS) [Select]
function KalphiterFunction()
{
    echo("HELLO WORLD1"):
    echo("HELLO WORLD2"):
}

What does this mean? First, to declare a function, you must use the keyword function. Then, you must add a function title. The function title must only contain letters or numbers.

Next, there are two parentheses. These are for parameters, which will be discussed later. The parentheses must be there no matter what.

Next, are the brackets. The curly brackets represent the opening and closing of this function.

In between them, is the echo() function. The quotes mean the start and end of a string. A string is literally a string of letters, or nurmbers, or symbols. This is considered a function parameter or argument. The final ";" ends an instruction.

Let's finally insert this script into the console:
Code: (TS) [Select]
function KalphiterFunction() { echo("HELLO WORLD1"): echo("HELLO WORLD2"): }      KalphiterFunction();
Notice how I used one line. Both consoles don't accept more than two-lined codes.

Notice how I also called the function by saying KalphiterFunction();. Calling a function executes the code inside it.


Also, you do not need to make a function, only for when you need it called periodically or something.




Variables/Comments
There may be a time where you would like to add a comment to your scripts.
Using // to start a comment will make everything from after the slashes to the end of the line a comment.

Example:
Code: (TS) [Select]
echo("HI"); //echo something... aertajen3j45vIf you know what block comments are, /* */, they are broken in Blockland.

What is a variable? A variable is a way to store text or numbers, or both.

Code: (TS) [Select]
%ourString = "Hello, this is ourString";
%ourNum = 5;
%ourRandomString = "Hello, eat "@ %ourNum @", LOL");
%ourFullString = %ourString @ %ourNum;
echo(%ourFullString);
Do you notice that a string has quotes? All text strings get quotes. A number does not need quotes, but it can still have them and nothing will happen.

In %ourRandomString, we add a %ourNum into the string.

In %ourFullString, we combine the two strings. We use the @ sign to seperate them.

This @ sign can be a few different things such as "TAB" and "SPC".

How long to variables last? Local variables, that use the percent sign, last as long as the script file or the function ends.

Global variables, which can be used from any script in any place of the game, use a $ sign.

Function: Exec
It is possible to use the exec() function to execute a script file. Steps:
Make a new text document. You should put it in the base folder or something, because Blockland only accepts scripts in default folders.

Change it's extension to .cs.

Paste the code into the file.

Type exec("yourfolder"); into the console.
Yourfolder should be like exec("base/scripts/myscript.cs");
« Last Edit: April 30, 2009, 10:55:16 PM by Kalphiter »

Crap, wrong section!!!

I'll just make everything tommorow.