The main functions of Blackey Script have been introduced.
I want to introduce the rest of the API here. Sometimes it is troublesome if lack these functions. (っ´ω`c)

# Functions

Function Description Example
print (expression1, …) Print the expression result to Log Window print(x);
random ( value ) Return a random number between 0 ~ (value-1) x = random(10);
msleep ( value ) Sleep for the given value of millisecond msleep(500);

## print (expressions)

First, let’s introduce the good friend of debug, the print function ~
You can use print function to print several expressions,
it will print each expression result in its’ prototype.

For the basic data types of Blackey Script, you can refer to this chapter.
Here are some simple examples:

x = 1;
y = pos(0.1, 0.2);
z = “Hello Blackey!”;
print(“x = “, x);
print(y, y);
print(z);

Print result:

x = , 1.000000
[(0.100000, 0.200000)] , [(0.100000, 0.200000)]
Hello Blackey!

## random (value)

Then we will talk about the random function.
Which is useful if you want to randomly determine the script behavior.
The way to use random function is also very simple, just fill in the range you expect,
the returned value will be a random number from 0 to (input value -1).
For example, if you want to get a random number from 1 to 10, you can write it like this:

randomValue = 1 + random(10);

random(10) will return a random number between 0~9, so just simply add 1 you can adjust the range from 1~10
If you are not sure whether this works, you can just write a simple script to verify it:

x = 0;
while (x < 10) {

print(x, random(10));
x = x+1;

}

Here is the result, you can see the minimum value 0 and the maximum value 9 had both print.

0.000000 , 0.000000
1.000000 , 4.000000
2.000000 , 6.000000
3.000000 , 2.000000
4.000000 , 6.000000
5.000000 , 7.000000
6.000000 , 5.000000
7.000000 , 6.000000
8.000000 , 9.000000
9.000000 , 8.000000

## msleep (value)

The last is the msleep function. As the name, it is used to sleep.
The timing is used when you want to delay the execution of the next expression,
In fact, we have used it several times in the previous examples.
During the recording mode, it will also automatically determine the interval between your actions and to fill the msleep.
The way to use it is very simple, you can sleep as long as what you fill. Z..z.(´-ω-`)

// Sleep randomly between 0.5 ~ 1.5 second
sleepTime = 500 + random(1000);
msleep(sleepTime);

You should notice that the unit of msleep is milliseconds (1/1000 sec),
However, if you really want to use the sleep function (with the unit second) …
We will teach you how to use custom functions to extend your own functions in the next chapter!