الانضمام إلى بوت الحرة مفتوحة المصدر المشروع في BotLibre.org
FAQ

How is Self different from JavaScript and JSON?

قبل admin نشر Apr 1 2022, 13:47

Bot Libre's scripting language Self is modeled after JavaScript, but is not JavaScript.

The syntax of Self is very similar to JavaScript, but it does have some different operators and behavior. One of these difference is related to Bot Libre's data model, which is similar to JavaScript's data model but does have some differences. These differences arise because Bot Libre's data model is designed specifically for artificial intelligence and allowing data to be represented similar to how the human brain works.

In JavaScript you can create a new object and assign a variable such as:

var Person = function() { };
var person = new Person();
person.name = "William";
person.name == "William"

In JavaScript the last line returns true.

In Self you do not need to declare classes, you can just use new. But everything else would be the same.

var person = new Person();
person.name = "William";
person.name == "William"

In Self the last line is also true.

How Self is different is that object variable can be assign multiple values.

person.name =+ "Will";
person.name == "Will"
person.name == "William"

The =+ operator is specific to Self, and allows you to assign addition values to a variable. In the above the person's name would be both Will and William. This is similar to the human brain, if I introduce myself as William, but them someone calls me Will, you would be okay with knowing my name is both Will and William.

Self can also have negative values.

person.name =- "Wally";
person.name == "Wally"

The last line will return false.

Self also understands the difference between knowing something is wrong, and not knowing something is right. In fact all relationships track a "correctness" decimal value between -1.0 and +1.0 which defines how certain the bot is about the relationship.

person.name == "Wilbur";

The last line will return #unknown. Boolean values can be the symbols #true, #false, and #unknown.

In Self because object variables can have multiple values the array notation can be used to access them.

person.name[0] == "William"
person.name[1] == "Will"

This can create some confusion when dealing with objects that have arrays, and in this case the Self syntax differs from the JavaScript syntax.

var person = { "name" : "Will", "children" : [ { "name" : "Will Jr." }, { "name" : "John" } ] };
person.children[0].name != "Will Jr."

Here children[0] means the first value of the children relationship, not the first value in the children array.

For arrays you can use the "elements" variable to traverse into the array elements.

person.children.elements[0].name == "Will Jr."

You could also use a variable to avoid the confusion. In general it is better to use variables when dealing with array to avoid confusion.

var children = person.children;
children[0].name == "Will Jr."

Here, because a variable was used, this is true.


by bemaouattara posted Mar 31, 19:22
Hello can you teach me more about bots and how to connect my website to the bot

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 311, today: 1, week: 11, month: 10

معرف: 42565876
Tags: javascript, self, json
نشر: Apr 1 2022, 13:47
تحديث: Apr 1 2022, 13:50
الردود: 1
الآراء: 1470, اليوم: 2, الأسبوع: 12, الشهر: 11
2 0 4.0/5