In-build functions

This detailed article will guide you how to use scripts effectively. The advanced and flexiable script controls that can define any action sequence and logical expressions as you want and activate them using your own advanced statements. such as Variable typeTypes of VariablesOperators and Statements

Type of variables

Blackey Script is a dynamically and strongly typed programming language.
And the syntax of the functions or methods is defined as similar to Python.
// Assign x as an integer
x = 1;
print(x);

// Assign x as a character
x = “Hello”;
print(x);
Console:
1.000000
Hello

Note

The dynamically-typed languages perform type checking at runtime, while statically typed languages perform type checking at compile time.
Such as C/C++, which require you to declare the data types of your variables before you use them, while dynamically-typed languages do not.
Strong type means that does not allow the programmer to get parameters of wrong type to code up and running. Take a wrong example below, we’re trying to add an integer and a string together.
x = 1 + “hello”

Basic types of Variables

Here are the basic types of Blackey Script-the floating-point and String, and two more derived types are Coordinate position and Region.

Type of variables

Syntax

Description

Number

x = 1;

Assign 1 as the value of x.

String

x = “Hello”

Assign ”Hello” as the value of x.(Double quotes are required.)

Position

x = pos(0.1, 0.3);

Assign the relative coordinate point (x,y)
the pointer arguments is position(x-axis value, y-axis value)
The top left corner of the screen is position(0.0)
pos(0.1,y) represents 10% from the left side of the screen.
pos(x,0.3) represents 30% from the top side of the screen.

Important

Please note that the above type of variables are valid, while some common types such as pointer, array, struct, class, etc., which are not yet supported within Blackey Scripts.

Built-in operators

With different conditions expressions often used to help create a logical expression that controls program flow. Therefore, in order to edit and customize your own scripts and operate it correctly, the following article will guide you on the practical use of the logical operators.

  • Arithmetic Operators

Description

Operator

Example

Multiplication

x = 1 * 2;

Division

/

x = 6 / 2;

Modulus

%

x = 5 % 3;

Addition

x = 1 + 2;

Subtraction

-

x = 1 – 2;

  • Relational Operators

Description

Operator

Example

Equality

==

x == 1

Not equal to

!=

x != 1

Greater than

>

x > 1

Less than

<

x < 1

Greater than equal to

>=

x >= 1

Less than equal to

<=

x <= 1

  • logical operators

Description

Operator

Example

Logical AND

&&

x && y

Logical OR

||

x || y

  • Others

Description

Operator

Example

Assignment operator

=

x = 1;

Apostrophe

,

x = 1, y = 2; print(x, y);

Function call

()

print(x);

Not equal to

-

x = -1; y = 1 * -3;

Note

Operations of Blackey Scripts are mostly similar to the C language, it defines precedence for all the operators and the operators with higher precedence are evaluated first as shown below:
x = 5;
y = z = 1 * -2 + 3 * 4 – -x;

Note:
We calculate -x firstly due to the unary operator with a higher precedence level get evaluated first. And calculate from right to left associativity.
The next arithmetic that we are going to calculate multiplication and perform the specified symbol in the end. (In mathematical terms, we know that division/multiplication will be carried out before addition/subtraction.)
Console: y=z=15

Expressions

Expressions can execute and manipulate program flow and evaluate results due to the C++ language-like syntax. Normally, code is executed from top to bottom, while it may jump to code in a different function.

There are four statements and examples

Expression statement

All expressions in an expression statement are evaluated and all side effects are completed before the next statement is executed. The most common expression statements are assignments and function calls.

x = 1;
y = 1 * 2;
print(y);

Selection statement

Blackey Script only supports if-else in select statement. An if-else statement controls conditional branching. Statements in the if-branch are executed only if the condition evaluates to a non-zero value (or true). If the value of condition is nonzero, the following statement gets executed, and the statement following the optional else gets skipped. Otherwise, the following statement gets skipped, and if there’s an else then the statement following the else gets executed.

  • Example

x = 1;
y = 2;
if (x < y) {

    print(“x 小於 y”);

} else {

    print(“x 大於等於 y”);

}

Console: x less than y

Tip

Please refer to the following 3 selection statements.

  • case1 If-statements

// If the expression is non-zero (true), run the if-statement.
if ( expression ) {

    statement1;
    …

}
  • case2 If-statements allow us to conditionally execute a block of code

// If the expression is non-zero (true), run the statement1,instead of the statement2.

if ( expression ) {

    statement1;
    …



} else {

    statement2;
    …

}
  • case3 If-statements allow us to conditionally execute a block of code

// If the expression is non-zero (true), run the statement1.

if ( expression ) {

    statement1;
    …
}


// If the expression2 is non-zero (true),run the statement2.

else if (expression2) {

    statement2;
        …
    }

// If both the expression1 and expression2 are zero (false), run the statement3.

else {

    statement3;
    …

    }

Iterator statement

Iteration statements cause statements (or compound statements) to be executed zero or more times, subject to some loop-termination criteria. We also call it while-loop, which can also terminate within Jump statement is executed. while loop is supported within an iteration syntax of Blackey Scripts

  • Example

...

x = 0;
while (x < 5) {     # while(expression)

    print(x);
    x = x + 1;

}

Console: 0, 1, 2, 3, 4

Jump statement

Jump statement performs an immediate local transfer of control.

  • syntax of Statements

Syntax

Description

break

The break statement ends execution of the nearest enclosing loop or conditional statement in which it appears.

continue;

Any remaining statements in the current iteration are not executed.

return[expression];

Terminates the execution of a function and returns the results and control to the calling function (or to the operating system if you transfer control from the main function).

  • The following code shows how to use the break statement:

...

x = 0;
while (x < 100) {

    print(x);
    x = x + 1;
    if (x > 5) {

print(“break out”);
break;

    }

}
print(“done”);

Console: 0, 1, 2, 3, 4, 5, “break out”, “done”

  • The following code shows how to use the continue statement:

...

x = 0;
while (x < 100) {

    x = x + 1;
    if (x > 5) {

        continue;

    }
    print(x);

}
print(“done”);

Console: 1, 2, 3, 4, 5, “done”

  • The following code shows how to use the return statement:

...

x = 0;
while (x < 100) {

    print(x);
    x = x + 1;
    if (x > 5) {

        print(“break out”);
        return 0;

    }

}
print(“done”);

Console: 0, 1, 2, 3, 4, 5, “break out”

Tip

In this program, return 0 ends the current program and jumps out of this block. Compared with the above example: break , ‘done’ won’t be printed.

  • The following code shows how to use the exit statement:

The exit functions terminate the calling process and usually use in custom functions. Typically, it is benefit for the caller sets the status value to 0 to indicate a exit status, print log on the console and monitor the errors.

...

def quitCheck(val) {

    if (val == 3) {

        exit(1);

    }

}

x = 0;
while (x < 100) {

    x = x + 1;
    quitCheck(x);
    print(x);

}
Console: 1, 2, 3, 4
exit(1) Console: [Line: 13] exit error code 1.000000



Visit Scripts or Back to the TOP