diff --git a/core/src/main.cpp b/core/src/main.cpp index 9c03cc1..4c818f5 100644 --- a/core/src/main.cpp +++ b/core/src/main.cpp @@ -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 { diff --git a/tutorial/01_shell_and_spy/README.md b/tutorial/01_shell_and_spy/README.md new file mode 100644 index 0000000..73cbb40 --- /dev/null +++ b/tutorial/01_shell_and_spy/README.md @@ -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; +``` diff --git a/tutorial/01_shell_and_spy/script.js b/tutorial/01_shell_and_spy/script.js new file mode 100644 index 0000000..c7eaa40 --- /dev/null +++ b/tutorial/01_shell_and_spy/script.js @@ -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(); diff --git a/tutorial/01_spies/README.md b/tutorial/01_spies/README.md deleted file mode 100644 index 09e15a9..0000000 --- a/tutorial/01_spies/README.md +++ /dev/null @@ -1,48 +0,0 @@ -Tutorial 01: Data and Spy -========================= - -This tutorial explain the role of data blocks and how to use the spy block. - -## Introduction - -The first type of block you need to learn is the RobotBlock. RobotBlock is a data block, it means the block provides data structure that can be used by other blocks. For example, RobotBlock provides a structure with general information about the robot. - -The SpyBlock is a usefull block that allow to interact with any BotJs block. SpyBlock has a special feature when connected to DataBlock. It shows inside data of the block and provide a way to changed it dynamicaly. - -To demonstrate the features of this two blocks, we are going to build a simple architecture with 1 RobotBlock and 2 SpyBlocks that spy the robot data. - -## Block architecture - -Every BotJs architecture can be represented as a block map. - -Blocks in the color map have a color code: - -- Blue : DataBlock -- Teal : SpyBlock -- Yellow : UiBlock - -![tutorial 01 architecture](doc/tutorial_01_architecture.png) - -## Run the demo script - -To run the demo - -```bash -botjs script.js -``` - -Two windows corresponding to the two spies should be opened. - -![tutorial 01 view](doc/tutorial_01_view.png) - -You can now change the name of the robot in one spy and you should see the name changed in the other spy. - -## The SHELL - -Through the shell you can access every created block. - -```js -botjs> Bot.data.name = 'je suis charlie' -``` - -After you have executed this command, spies should have update their view to print the new name. diff --git a/tutorial/01_spies/doc/tutorial_01_architecture.png b/tutorial/01_spies/doc/tutorial_01_architecture.png deleted file mode 100644 index 4850e31..0000000 Binary files a/tutorial/01_spies/doc/tutorial_01_architecture.png and /dev/null differ diff --git a/tutorial/01_spies/doc/tutorial_01_view.png b/tutorial/01_spies/doc/tutorial_01_view.png deleted file mode 100644 index c540682..0000000 Binary files a/tutorial/01_spies/doc/tutorial_01_view.png and /dev/null differ diff --git a/tutorial/01_spies/script.js b/tutorial/01_spies/script.js deleted file mode 100644 index 0add5f5..0000000 --- a/tutorial/01_spies/script.js +++ /dev/null @@ -1,22 +0,0 @@ -// Enable logging -// core.logTalking = true - -// core.create("shell", "agent007"); - -// Create spies -core.create("spy", "agent007"); -core.create("spy", "agent008"); -// // core.create("spy", "agent009"); - -agent007.logTalking = true -agent008.logTalking = true - -// Connect spies to robot -agent007.connect(core); -// agent008.connect(agent009); -// agent009.connect(agent007); - -// Display spies -agent007.show(); -// agent008.show(); -// agent009.show();