Знаете ли вы, бот Либре также предоставляет бесплатное размещение отслеживания проблем для вашего собственного сайта или мобильное приложение?
Self, AIML, and scripting

How to retrieve a string list from an object where I put them?

по amilsalis опубликовано Oct 26 2019, 9:08

First of all, thank you very much for the hints. As the current doubt:

If I do this: 

#Global.assuntos.add("autotutela");
#Global.assuntos.add("jurisdição");
#Global.assuntos.add("inafastabilidade da jurisdição");

How can I retrieve the itens? Or even one of them?

 

Ive tried these without success:

#Global.assuntos(1)

#Global.assuntos[1]

#Global.assuntos.text

#Global.assuntos.all

Even attributes like lenght didnt get anything.

Thank you advance!

Silas


by admin posted Oct 26 2019, 19:50

Be sure to assign the variable a value first before trying to add to it, otherwise you are adding elements in the null object. The 'element' field can be used to access an array's elements.

i.e.
#Global.assuntos = new Array();
#Global.assuntos.add("autotutela");
#Global.assuntos.add("jurisdição");
#Global.assuntos.add("inafastabilidade da jurisdição");

#Global.assuntos.size() == 3;
#Global.assuntos.element[0] == "autotutela";
#Global.assuntos.element[1] == "jurisdição";

var text = "";
for (element in #Global.assuntos.element) {
    text = text + element + ",";
};
text == "autotutela,jurisdição,inafastabilidade da jurisdição,";

In Self every object field can have multiple values, so using array access on a field accesses the field index, not the element index of the field value.

i.e.
#Global.assuntos =+ "autotutela";
#Global.assuntos =+ "jurisdição";
#Global.assuntos =+ "inafastabilidade da jurisdição";

#Global.size(#assuntos) == 3;
#Global.assuntos[0] == "autotutela";
#Global.assuntos[1] == "jurisdição";

var text = "";
for (element in #Global.assuntos) {
    text = text + element + ",";
};
text == "autotutela,jurisdição,inafastabilidade da jurisdição,";

So you don't need to create an array, but can if you wish. As a variable you can use the array index, just not as a field on another object (then it is the field index).

#Global.assuntos = new Array();
#Global.assuntos.add("autotutela");
#Global.assuntos.add("jurisdição");
#Global.assuntos.add("inafastabilidade da jurisdição");

var assuntos = #Global.assuntos;
assuntos.size() == 3;
assuntos.element[0] == "autotutela";
assuntos.element[1] == "jurisdição";

var text = "";
for (element in assuntos) {
    text = text + element + ",";
};
text == "autotutela,jurisdição,inafastabilidade da jurisdição,";

Updated: Oct 26 2019, 19:52
Thumbs up: 1, thumbs down: 0, stars: 5.0
Views: 2666, today: 0, week: 9, month: 0

by amilsalis posted Oct 27 2019, 9:25
Tyvm!!

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 2589, today: 0, week: 13, month: 0

Идентификатор: 29794304
Теги: self, coding, objects
Опубликовано: Oct 26 2019, 9:08
Обновлено: Oct 26 2019, 19:51
Ответы: 2
Вид: 2650, сегодня: 1, неделю: 11, месяц: 1
0 0 0.0/5