Skip to content

Commit 19a8cee

Browse files
committed
[5] Update tutorial 1
1 parent 1728fee commit 19a8cee

File tree

7 files changed

+112
-71
lines changed

7 files changed

+112
-71
lines changed

core/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
4949
#endif
5050

5151
// Default script shell
52-
app.js()->eval("");
52+
app.js()->eval("core.create('shell', 'shell'); shell.start();");
5353
}
5454
else
5555
{

tutorial/01_shell_and_spy/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Tutorial 01: Shell and Spy
2+
=========================
3+
4+
This tutorial explain how to create your first JS script to configure BotJs. It describes 2 of the most usefull block of BotJs Shell and Spy.
5+
6+
## The Shell
7+
8+
At this point you have build and install BotJs in your environment. You have test it by simply executing BotJs.
9+
10+
```bash
11+
botjs
12+
```
13+
14+
In your shell BotJs prompt has appeared.
15+
16+
```bash
17+
TODO
18+
botjs>
19+
```
20+
21+
_Ok but why is there a BotJs prompt shell? I thought that BotJs was empty at start._
22+
23+
Yes it is true, BotJs is empty at start up. But when BotJs is executed without arguments, it loads its own configuration script. This simple script is provided below. It just starts the shell to allow user to configure the application.
24+
25+
```js
26+
core.create("shell", "shell");
27+
shell.start();
28+
```
29+
30+
Every loadable module in BotJs is called a Block. Core is the first loaded block, it contains every other blocks of the application. Blocks can create other blocks with create function. The first argument of this function is the typename of the block and the second the name of the block (the name of its variable).
31+
32+
```js
33+
// Create 3 shell block with 3 different names
34+
35+
core.create("shell", "shell");
36+
37+
core.create("shell", "variableShell");
38+
39+
core.create("shell", "FOO");
40+
```
41+
42+
When core create a block, this block is directly accessible through javascript.
43+
44+
```js
45+
// Start the shell prompt
46+
shell.start();
47+
```
48+
49+
But the block is also a sub block of core block. Therefore it is accessible with block function.
50+
51+
```js
52+
// Start the shell prompt
53+
core.block('shell').start();
54+
```
55+
56+
## The Spy
57+
58+
To monitor your block architecture you can type javascript command through the shell and ask one by one information. Or use a Spy Block and get real time information !
59+
60+
A Spy can be created like any other block.
61+
62+
```js
63+
// Create a spy
64+
core.create("spy", "agent007");
65+
```
66+
67+
One Spy can spy one block at time. To spy a block use connect function.
68+
69+
```js
70+
// Spy core block
71+
agent007.connect(core);
72+
```
73+
74+
Then to display the spy:
75+
76+
```js
77+
// Spy core block
78+
agent007.show();
79+
// or
80+
agent007.visible = true;
81+
```
82+
83+
## Log System
84+
85+
Every block can log its activities on a file and/or in a the shell.
86+
87+
```js
88+
// agent007 will log in its log file
89+
// In linux: $HOME/opt/botjs/log/agent007
90+
agent007.logEnable = true;
91+
// agent007 will log in its log file and will print in cout
92+
agent007.logTalking = true;
93+
```

tutorial/01_shell_and_spy/script.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Create the shell
2+
core.create("shell", "shell");
3+
4+
// Create spies
5+
core.create("spy", "agent007");
6+
core.create("spy", "agent008");
7+
8+
agent007.logTalking = true
9+
10+
// Connect spies to robot
11+
agent007.connect(agent008);
12+
agent008.connect(core);
13+
14+
// Display spies
15+
agent007.show();
16+
17+
// Start shell
18+
shell.start();

tutorial/01_spies/README.md

Lines changed: 0 additions & 48 deletions
This file was deleted.
Binary file not shown.
-22.9 KB
Binary file not shown.

tutorial/01_spies/script.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)