Skip to content

Commit

Permalink
[5] Update tutorial 1
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Feb 7, 2015
1 parent 1728fee commit 19a8cee
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 71 deletions.
2 changes: 1 addition & 1 deletion core/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char *argv[])
#endif

// Default script shell
app.js()->eval("");
app.js()->eval("core.create('shell', 'shell'); shell.start();");
}
else
{
Expand Down
93 changes: 93 additions & 0 deletions tutorial/01_shell_and_spy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Tutorial 01: Shell and Spy
=========================

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.

## The Shell

At this point you have build and install BotJs in your environment. You have test it by simply executing BotJs.

```bash
botjs
```

In your shell BotJs prompt has appeared.

```bash
TODO
botjs>
```

_Ok but why is there a BotJs prompt shell? I thought that BotJs was empty at start._

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.

```js
core.create("shell", "shell");
shell.start();
```

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).

```js
// Create 3 shell block with 3 different names

core.create("shell", "shell");

core.create("shell", "variableShell");

core.create("shell", "FOO");
```

When core create a block, this block is directly accessible through javascript.

```js
// Start the shell prompt
shell.start();
```

But the block is also a sub block of core block. Therefore it is accessible with block function.

```js
// Start the shell prompt
core.block('shell').start();
```

## The Spy

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 !

A Spy can be created like any other block.

```js
// Create a spy
core.create("spy", "agent007");
```

One Spy can spy one block at time. To spy a block use connect function.

```js
// Spy core block
agent007.connect(core);
```

Then to display the spy:

```js
// Spy core block
agent007.show();
// or
agent007.visible = true;
```

## Log System

Every block can log its activities on a file and/or in a the shell.

```js
// agent007 will log in its log file
// In linux: $HOME/opt/botjs/log/agent007
agent007.logEnable = true;
// agent007 will log in its log file and will print in cout
agent007.logTalking = true;
```
18 changes: 18 additions & 0 deletions tutorial/01_shell_and_spy/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Create the shell
core.create("shell", "shell");

// Create spies
core.create("spy", "agent007");
core.create("spy", "agent008");

agent007.logTalking = true

// Connect spies to robot
agent007.connect(agent008);
agent008.connect(core);

// Display spies
agent007.show();

// Start shell
shell.start();
48 changes: 0 additions & 48 deletions tutorial/01_spies/README.md

This file was deleted.

Binary file removed tutorial/01_spies/doc/tutorial_01_architecture.png
Binary file not shown.
Binary file removed tutorial/01_spies/doc/tutorial_01_view.png
Binary file not shown.
22 changes: 0 additions & 22 deletions tutorial/01_spies/script.js

This file was deleted.

0 comments on commit 19a8cee

Please sign in to comment.