Difference between revisions of "Kray3 SDK/Script basics"

From Kray
Jump to: navigation, search
(Functions)
(Script Basics)
Line 3: Line 3:
 
Welcome to Kray3 Script! Kray script is scripting language that allows you to control Kray render engine. It is very easy to use it so anyone can try it, although any previous programming background experience will come handy.
 
Welcome to Kray3 Script! Kray script is scripting language that allows you to control Kray render engine. It is very easy to use it so anyone can try it, although any previous programming background experience will come handy.
  
In this first section we will explore basic data types and operations that you can use in Kray Script.
+
All you need to start writing Kray scripts is a text editor. I recomend one with code highlighting like [http://notepad-plus-plus.org/ Notepad++].
 +
 
 +
When writing scripts you should make sure you always end your lines with semicolon ';'. Without semicolon Kray will report an error.
 +
 
  
 
== Data Types ==
 
== Data Types ==
You can use all the standard data types in Kray. Here is just a quick description of each of them:
+
In this first section we will explore basic data types and operations that you can use in Kray Script. You can use all the standard data types in Kray. Here is just a quick description of each of them:
  
 
=== Strings ===
 
=== Strings ===
Line 12: Line 15:
  
 
  "this is string";
 
  "this is string";
  'this is also string'
+
  'this is also string';
  
 
=== Double ===
 
=== Double ===
Line 81: Line 84:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Function can also optionaly take some arguments:
+
Function can also optionaly take some arguments. You define arguments that script can take by defining it's data type and name inside the round brackets:
  
 
<syntaxhighlight>
 
<syntaxhighlight>
Line 88: Line 91:
 
  string part2, "and second string.";
 
  string part2, "and second string.";
  
  function MergeStrings(string1, string2){  
+
  function MergeStrings(string string1, string string2){  
 
   echo string1 + string2; // whenever we call the function this line will get executed
 
   echo string1 + string2; // whenever we call the function this line will get executed
 
  }
 
  }
  
  // We can execute the function by calling it's name and passing it arguments:
+
  // We execute the function by calling it's name and passing it arguments:
 
  MergeStrings(part1,part2);
 
  MergeStrings(part1,part2);
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 15:41, 15 August 2012

Script Basics

Welcome to Kray3 Script! Kray script is scripting language that allows you to control Kray render engine. It is very easy to use it so anyone can try it, although any previous programming background experience will come handy.

All you need to start writing Kray scripts is a text editor. I recomend one with code highlighting like Notepad++.

When writing scripts you should make sure you always end your lines with semicolon ';'. Without semicolon Kray will report an error.


Data Types

In this first section we will explore basic data types and operations that you can use in Kray Script. You can use all the standard data types in Kray. Here is just a quick description of each of them:

Strings

Strings can be used by wrapping them in singe ' or double " quote marks. For example:

"this is string";
'this is also string';

Double

Double is a type of number that contains twice as many binary digits. You will mostly use this type of number.

<syntaxhighlight>

var pi, 3.14159;
echo pi;

</syntaxhighlight>

Vector

Vectors are used to define position in space. Whenever you need to use vectors in Kray script you need to declare them with vector command in round brackets: (x,y,z)

<syntaxhighlight>

vector myvector, <1,2,3>;

</syntaxhighlight>

Orientation/Axes

Orientation matrix or axes defines orientation in space with heading, pitch and bank values. You declare orientation with 'axes' command and values (degrees) in angled brackets:

<syntaxhighlight>

axes south, <180,0,0>;

</syntaxhighlight>

Orientation is rotation matrix of x,y and z vector. You can lookup each of the vectors like this:

<syntaxhighlight>

echo <0,0,0>.x // returns X vector in the matrix: (1,0,0)
echo <0,0,0>.y // returns Y vector in the matrix: (0,1,0)
echo <0,0,0>.z // returns Z vector in the matrix: (0,0,1)

</syntaxhighlight>

Arithmetic operations

Several standard operations can be used on data types. Please see the following section for details:

Arithmetic operations

Variables

Declaring variables in Kray Script is much like in any other language. The following commands are available for each of the data types:

<syntaxhighlight>

// String variable:
string sometext, "we just declared a string";
// Double variable:
double somenumber, 3.14159;
// Vector variable:
vector somevector, (1,0,1);
// Orientation variable:
axes northwest, (-45,0,0);

</syntaxhighlight>

Functions

Kray Script allows you to write your own functions. Functions are small parts of the code that can be called and executed at will. Think of it like part of the code that you can call with a single command.

To create a function you have to give it a name and wrap it in curly braces:

<syntaxhighlight>

function MyFirstFunction(){ 
 // ... here we will write some code
}

</syntaxhighlight>

Function can also optionaly take some arguments. You define arguments that script can take by defining it's data type and name inside the round brackets:

<syntaxhighlight>

// Lets define two strings that we will pass to function
string part1, "first string ";
string part2, "and second string.";
function MergeStrings(string string1, string string2){ 
 echo string1 + string2; // whenever we call the function this line will get executed
}
// We execute the function by calling it's name and passing it arguments:
MergeStrings(part1,part2);

</syntaxhighlight>

Loops and Conditional statements

There are two statements available in Kray script: IF and WHILE:

while

Executes code as long as condition is true

while {....}

if

Executes code if condition is true.

if {... }

Common commands

echo

help