Blockland Forums > Modification Help

I need a teacher

Pages: << < (3/4) > >>

Freeze:


--- Quote from: SkullCandy on September 22, 2010, 08:37:03 AM ---Well NPC, it is better if you learn on your own, but, if you really need a teacher I can teach a bit.

--- End quote ---
I can imagine you being an evil teacher.

*SIT DOWN CHILDREN AND SHUT UP. TODAY WE ARE GOING TO LEARN SCRIPTING. IS THAT CHEWING GUM. SPIT IT OUT RIGHT NOW. *belt**

lordician:


--- Quote from: Freeze on October 01, 2010, 03:29:52 AM ---I can imagine you being an evil teacher.

*SIT DOWN CHILDREN AND SHUT UP. TODAY WE ARE GOING TO LEARN SCRIPTING. IS THAT CHEWING GUM. SPIT IT OUT RIGHT NOW. *belt**

--- End quote ---
You don't know anything about scripting.
Shut up. :S

Wesley Williams:

Scripting in a nutshell: (of what I know so far)

% = Local Variable (ends once the function is ended)
$ = Global Variable (is used throughout the entire code)
True = 1 (boolean)
False = 0 (boolean)


Call a function:


--- Code: ---function()
{
    //Write the code here
}
--- End code ---

Use variables in a function:


--- Code: ---function(example)
{
    %LocalVariable1 = "This is the string data being entered into %LocalVariable1!";

    $GlobalVariable1 = "This is the string data being entered into $GlobalVariable1!";
   
    echo("This is the string data being entered into the echo function!");
}

--- End code ---


--- Code: ---function(example2)
{
    %localVariable1 = 2000;
    %localVariable2 = "Local String Data!";

    $globalVariable1 = 20;
    $globalVariable2 = "Global String Data!";

    echo(%localVariable1);
    echo(%localVariable2);
    echo($globalVariable1);
    echo($globalVariable2);
}
--- End code ---

This will echo:
2000
Local String Data!
20
Global String Data!


Visual:

To visually see this work, try adding a "TEST.cs" file into your Blockland folder under "config" using this code:
(edit with Notepad)

--- Code: ---//TEST.cs

function test()
{
    %localvar1 = 500;
    %localvar2 = "Local Data Collected!";

    $globalvar1 = 1000;
    $globalvar2 = "Global Data Collected!";

    echo(%localvar1);
    echo(%localvar2);
    echo($globalvar1);
    echo($globalvar2);
}

--- End code ---

Then start Blockland, and type [exec("config/test.cs");] into the console. It will then say "Executing TEST.cs." Then Test(); to start the test. *Note: Your Blockland folder must be the only folder before "config" for this to work! Otherwise, type in [exec("(folder)/config/test.cs");]

This should appear:



IF, IF THEN, & IF THEN IF conditional statements:

IF - executes code if the IF condition is true
IF ELSE - executes code if the IF condition is false
IF ELSE IF - may not execute the ELSE statement even if the IF condition is false!


--- Code: ---if(example3)
{
    //Code is written here.
}

--- End code ---


--- Code: ---ifexample4)
if()
{
    //Code is written here.
}
else
{
    //Code is written here.
}

--- End code ---


--- Code: ---function(example5)
if()
{
    //Code is written here.
}
else if()
{
    //Code is written here.
}

--- End code ---

Real example:

--- Code: ---if(3>10)
  echo("IF statement executed and was true!");
else if(4>10)
   echo("IF statement executed and was false!!");
else
    echo("IF statement executed and the ELSE IF was false!");
--- End code ---

In this example, the IF and ELSE IF statements are false, and only the echo after the ELSE statement is executed.
*Note: Brackets are not required when a statement only has one piece of code.


Operators:

== - equals (only one equal sign can cause issues)
&& - and (both must be true!)
|| - or (only one must be true!)
NOT - converts the condition to the opposite it represents (True/False)
SPC - combines two values with a space
@ - combines two values together to form a new value
NL - Concatenates one value together with a new line to form a new value.
TAB - Concatenates one value together with a tab to form a new value.
$= -  Evaluates whether string1 is equal to string2
!$= Evaluates whether string1 is not equal to string2.

*Note: The basic math symbols are also used. (+, -, *, /, =, >, <)

Notes:
*Use // to make notes (does not affect the script)
*Scripts must be a .cs file. To make a .cs file simply create a .txt file and edit the ending to .cs!
*Another type of conditional statement is a switch statement, but I do not yet know what these do.
*To be a good script writer, you will need to know much more than this - these are just the basics.


For a better and much more in-depth tutorial, check out KINEX's Scripting Tutorials.
This was taken directly from his tutorials. (Packed together)

Hazmat:

i wish to learn scripting as well how would i learn it myself without a teacher?


Gadgethm:

You can take a look at pieces of code.  There are also plenty of online tutorials, and some great references.

http://forum.blockland.us/index.php?topic=108156.0
http://www.egotron.com/torque/old_script.html#removeWord

Pages: << < (3/4) > >>

Go to full version