AVATAR Forum
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le Deal du moment : -28%
Précommande : Smartphone Google Pixel 8a 5G ...
Voir le deal
389 €

aide a la boucle for let

2 participants

Aller en bas

aide a la boucle for let Empty aide a la boucle for let

Message par halim Mar 18 Avr - 14:39

bonjour, stephane,  j'ai creer un plugin avec plusieurs speak je voudrais le réduire avec la boucle for let pour qu'il me dicte aleatoire les speak, parceque avec la boucle for let il me dicte le premier speak les autres il les saute
exemple:

for(let i=0;i<5;i++) {
let classement = $('div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').eq(i).text();
let points = $('div.GeneralStats-item.GeneralStats-item--points').eq(i).text();
Avatar.speak("classement + ".avec." + points + ".point", data.client, function(){
Avatar.Speech.end(data.client);
//askContinue (data, client);
});
}

let classement = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(1) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement1 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(2) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement2 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(3) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let point = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(1) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point1 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(2) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point2 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(3) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
Avatar.speak("Premié." + classement + ".avec." + point + "point", data.client, function(){
Avatar.speak("Deuziemme." + classement1 + ".avec." + point1 + ".point", data.client, function(){
Avatar.speak("Troiziemme." + classement2 + ".avec." + point2 + ".point", data.client, function(){
Avatar.Speech.end(data.client);
askContinue (data, client);
});
});
});
halim
halim

Messages : 93
Date d'inscription : 19/11/2022

Revenir en haut Aller en bas

aide a la boucle for let Empty Re: aide a la boucle for let

Message par Avatar Mar 18 Avr - 18:00

Slt Halim,

Ton dev est un peu confus… je n'y comprend rien.
Mais ce que je peux te dire c'est que dans un speak , tu peux séparer les speech pas un | pour qu'ils soient lu aléatoirement
exemple:
Avatar.speak("je dis 1|je dis 2|je dis 3", data.client, function(){
   //do stuff
});

Après, à toi de construire la chaine avec un séparateur |
Tu devrais consulter la doc avant parce que c'est dans la document de dev Smile
Avatar
Avatar

Messages : 81
Date d'inscription : 01/09/2020
Age : 58
Localisation : Toulouse

Revenir en haut Aller en bas

aide a la boucle for let Empty Re: aide a la boucle for let

Message par halim Mar 18 Avr - 18:19

rebonjour stephane , je ne voulais pas mettre tout le dev , parceque il y'a au moins 100 lignes de code

exports.action = function(data, callback){

var tblCommand = {
classementfoot : function() {classementfoot (data, client);
},
resultatfoot : function() {resultatfoot (data, client);
}
};

let client = setClient(data);
info("FootBall:", data.action.command, "From:", data.client, "To:", client);
tblCommand[data.action.command]();
callback();
}

function classementfoot (data, client) {

let url = 'https://www.ligue1.fr/classement';
let request = require('request');
request({ 'uri' : url, 'headers':{'Accept-Charset': 'utf-8'}}, function (err, response, body){
if(err || response.statusCode != 200) {
Avatar.speak("je n'arrive pas accedé au site", data.client, function(){
Avatar.Speech.end(data.client);
});
return;
}
if(response) {
let $ = require('cheerio').load(body, { xmlMode: true, ignoreWhitespace: false, lowerCaseTags: false });
let classement = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(1) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement1 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(2) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement2 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(3) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement3 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(4) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement4 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(5) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement5 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(6) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let point = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(1) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point1 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(2) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point2 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(3) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point3 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(4) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point4 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(5) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point5 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(6) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
Avatar.speak("Premiére place." + classement + ".avec." + point + "point", data.client, function(){
Avatar.speak("Deuziemme place." + classement1 + ".avec." + point1 + ".point", data.client, function(){
Avatar.speak("Troiziemme place." + classement2 + ".avec." + point2 + ".point", data.client, function(){
Avatar.speak("Quatriemme place." + classement3 + ".avec." + point3 + ".point", data.client, function(){
Avatar.speak("Cinquiemme place." + classement4 + ".avec." + point4 + ".point", data.client, function(){
Avatar.speak("Siziemme place." + classement5 + ".avec." + point5 + ".point", data.client, function(){
Avatar.Speech.end(data.client);
askContinue (data, client);
});
});
});
});
});
});
}
});

return;
}

function classementfoot2 (data, client) {

let url = 'https://www.ligue1.fr/classement';
let request = require('request');
request({ 'uri' : url, 'headers':{'Accept-Charset': 'utf-8'}}, function (err, response, body) {
if(err || response.statusCode != 200) {
Avatar.speak("je n'arrive pas accedé au site", data.client, function(){
Avatar.Speech.end(data.client);
});
return;
}
if(response) {
let $ = require('cheerio').load(body, { xmlMode: true, ignoreWhitespace: false, lowerCaseTags: false });
let classement7 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(7) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement8 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(Cool > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement9 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(9) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement10 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(10) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement11 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(11) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let classement12 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(12) > a > div.GeneralStats-item.GeneralStats-item--club > span.GeneralStats-clubName.desktop-item').first().text();
let point7 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(7) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point8 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(Cool > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point9 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(9) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point10 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(10) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point11 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(11) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
let point12 = $('body > main > div > div.component.filter-rankingPage > div.container.page-section > div > div > div > div.GeneralStats-table > div.classement-table-body > ul > li:nth-child(12) > a > div.GeneralStats-item.GeneralStats-item--points').first().text();
Avatar.speak("Setiemme." + classement7 + ".avec." + point7 + "point", data.client, function(){
Avatar.speak("Huitiemme." + classement8 + ".avec." + point8 + ".point", data.client, function(){
Avatar.speak("Neuviemme." + classement9 + ".avec." + point9 + ".point", data.client, function(){
Avatar.speak("Diziemme." + classement10 + ".avec." + point10 + ".point", data.client, function(){
Avatar.speak("Onziemme." + classement11 + ".avec." + point11 + ".point", data.client, function(){
Avatar.speak("Douziemme." + classement12 + ".avec." + point12 + ".point", data.client, function(){
Avatar.Speech.end(data.client);
});
});
});
});
});
});
}
});
return;
}


function askContinue (data, client) {
Avatar.askme("Tu veux que je continue ?", data.client, {
"oui": "yes",
"oui s'il te plait": "yes",
"encore": "yes",
"oui encore": "yes",
"non": "done",
"non merci": "done",
"ca seras tout": "done",
"non ca seras tout": "done",
"c'est bon": "don",
"non c'est bon": "done",
"terminer": "done"
}, 0, function (answer, end) {

// Grammaire fixe
switch(answer) {
case "yes":
classementfoot2 (data, client);
break;

case "done":
default:
Avatar.speak("Terminé", data.client, function(){
end(data.client, true);
});
}
});

}


function resultatfoot (data, client) {

}


function setClient(data){
var client = data.client;
if (data.action.room)
client = (data.action.room != 'current') ? data.action.room : (Avatar.currentRoom) ? Avatar.currentRoom : Config.default.client;
if (data.action.setRoom)
client = data.action.setRoom;
return client;
}
halim
halim

Messages : 93
Date d'inscription : 19/11/2022

Revenir en haut Aller en bas

aide a la boucle for let Empty Re: aide a la boucle for let

Message par Avatar Mar 18 Avr - 18:25

C'est encore pire... Smile
Tu as déjà ma réponse à ta question de lire des speech aléatoirement.
Avatar
Avatar

Messages : 81
Date d'inscription : 01/09/2020
Age : 58
Localisation : Toulouse

Revenir en haut Aller en bas

aide a la boucle for let Empty Re: aide a la boucle for let

Message par halim Mar 18 Avr - 18:32

execuse moi stephane pas aleatoire je me suis mal exprimé je veux dire consecutif

premiere place // ensuite
deuxieme place // ensuite
troisieme place // ect ...
........
........
halim
halim

Messages : 93
Date d'inscription : 19/11/2022

Revenir en haut Aller en bas

aide a la boucle for let Empty Re: aide a la boucle for let

Message par Avatar Mar 18 Avr - 19:47

et bien tu fais ca:

Avatar.speak("dis 1", data.client, function(){
  Avatar.speak("dis  2", data.client, function(){
  Avatar.speak("dis 3", data.client, function(){
      Avatar.Speech.end(data.client);
  })
})
});

et si tu ne connais pas le nombre de speak tu peux faire une boucle:
let tblSpeak = ['dis 1','dis 2','dis 3'];
for (let i=0; i<tblSpeak.length; i++) {
  Avatar.speak(tblSpeak[i], data.client);
}
Avatar.Speech.end(data.client);

bien sur, il faut mettre tes speech dans un tableau, par exemple par un tblSpeak.push
Peut-être aussi mais ça c'est a tester, mettre un timeout entre chaque speak pour qu'avatar reprenne son souffle... a toi de voir
for (let i=0; i<tblSpeak.length; i++) {
 setTimeout(() => {
   Avatar.speak(tblSpeak[i], data.client);
 }, "1000")
}

Et en dev, il est toujours bon de mettre un console.log pour savoir ce qui est récupéré parce que là, dans ton dev, tu ne sais pas si tu récupère quelque chose à dire et donc tu peux penser que ca ne fonctionne pas alors que ben... il n'y a rien à dire Very Happy
Ca veut dire aussi que tu dois tester si la chaîne est vide ou non avant de faire un speak.
Un bon développeur ne fait pas que du dev...
C'est la différence entre un développeur du dimanche et un bon développeur. Un bon développeur gère correctement les exceptions.
Avatar
Avatar

Messages : 81
Date d'inscription : 01/09/2020
Age : 58
Localisation : Toulouse

Revenir en haut Aller en bas

aide a la boucle for let Empty Re: aide a la boucle for let

Message par halim Mer 19 Avr - 11:41

bonjour, stephane, j'ai réussis mais autrement, ce qui me poser le premier probleme , c'est la variable let, que j'ai remplacer par var (bizarre)
j'ai plus de 50 lignes de codes de moins(au moins)

il reste aussi un tout petit soucis a L'instruction break , il s'arrete pas tout a fait , et aussi a rajouter une fonction pour le résultat des matches
je te tiens au courant pour cela

merci stephane pour ton aide et d'etre toujour a l'ecoute et aussi présent sur le forum AVATAR (parce que les autres forums sont desert , aucune activités , aucun développement , aucun nouveau plugin , aucune mise a jours de leurs plugins ou de leurs systeme Very Happy

ps: dommage les utilisateurs de sarah ou jarvis ne savent pas c'est quoi le Nlp, sinon depuis longtemps sont passer sur AVATAR
https://intelligence-artificielle.com/nlp-guide-complet/
a plus
halim
halim

Messages : 93
Date d'inscription : 19/11/2022

Revenir en haut Aller en bas

aide a la boucle for let Empty Re: aide a la boucle for let

Message par Avatar Mer 19 Avr - 12:08

let a une portée dans le block où il déclare la variable.
var a une portée globale dans la fonction

ainsi tu peux faire:
function test() {
if (..........) {
let a = 0;
}

if (..........) {
let a = 1;
}

}

et tu peux faire:
function test() {
var a;
if (..........) {
a = 0;
}

if (..........) {
a = 1;
}

}


Avatar
Avatar

Messages : 81
Date d'inscription : 01/09/2020
Age : 58
Localisation : Toulouse

Revenir en haut Aller en bas

aide a la boucle for let Empty Re: aide a la boucle for let

Message par Contenu sponsorisé


Contenu sponsorisé


Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum