简体   繁体   English

我可以在 Inline Fulfillment Dialogflow 编辑器中跨对话存储计数器吗?

[英]Can I store a counter across conversation in Inline Fulfillment Dialogflow editor?

I'm making a multiplayer quiz in dialogflow using the inline editor.我正在使用内联编辑器在对话流中进行多人测验。 For now, I have round 1 and 2 working but the score counting not yet.目前,我已经完成了第 1 轮和第 2 轮的工作,但还没有计分。

So maybe it's stupid but I thought 'oh I will make a var and store a count in that.所以也许这很愚蠢,但我想'哦,我会制作一个 var 并在其中存储一个计数。 Every time a function is at a good answer de count will do ++ etc etc."每次 function 是一个很好的答案时,计数都会做 ++ 等等。”

I made a snippet with 2 questions so you understand my problem.我制作了一个包含 2 个问题的片段,以便您了解我的问题。 I've read much about oh you have to store it in user storage but I don't understand how.我读过很多关于哦,你必须将它存储在用户存储中,但我不明白如何。 Already read the documentation of dialogflow but I'm not that much technical so it's hard.已经阅读了 dialogflow 的文档,但我的技术含量不是很高,所以很难。

  var pointsp1 = 0;
  var pointsp2 = 0;

//round 2 player 1

  function vraag1triva(agent) {  
  const goed = agent.parameters.goed;
  const fout = agent.parameters.any;


    if (goed=='tv tas') {
     pointsp1++;
      agent.add("<speak><audio src=\"https://actions.google.com/sounds/v1/transportation/ship_bell.ogg\"></audio>uit welk land komt de avocado?</speak>");
    } else if (fout) {
        agent.add("Je antwoord is fout, het juiste antwoord was tv-tas,uit welk land komt de avocado?");
    }
  }
  //round 2 player 2
  function vraag2triva(agent) {  
    const goed = agent.parameters.goed;
    const fout = agent.parameters.any;
      if (goed=='mexico') {
        pointsp2++;
          agent.add("Goedzo, Mexico is het juiste antwoord. Van wie is het nummer Don't worry, be happy?");
      } else if (fout) {
          agent.add("Je antwoord is fout, het juiste antwoord was mexico, Van wie is het nummer Don't worry, be happy?");
      }
  }
 //score
  function totalscore(agent) {  
    if (pointsp1>pointsp2) {
      agent.add("Player 1 wins"); 
    }else if (pointsp1<pointsp2)
      agent.add("Player 2 wins");
  }

I expected that when I would call the function 'total scores'.我预计当我将 function 称为“总分”时。 It says which player had won the round according to the most good answers.它会根据最佳答案显示哪个玩家赢得了回合。

edit, tried user storage:编辑,尝试用户存储:

let conv = agent.conv(); // create an instance
    conv.data.pointspt1 = 0;
    conv.data.pointsp2 = 0;

   //score
  function totalscore(agent) {  
    if (conv.data.pointsp1>conv.data.pointsp2) {
      agent.add("Player 1 wins round 2"); 
    }else if (conv.data.pointsp1<conv.data.pointsp2)
      agent.add("Player 2 wins round2");
  }


//round 2 player 1

  function vraag1triva(agent) {  
  const goed = agent.parameters.goed;
  const fout = agent.parameters.any;

    if (goed=='tv tas') {
    //save score
      agent.add("<speak><audio src=\"https://actions.google.com/sounds/v1/transportation/ship_bell.ogg\"></audio>uit welk land komt de avocado?</speak>");
      conv.user.storage.pointspt1++; 
    } else if (fout) {
        agent.add("Je antwoord is fout, het juiste antwoord was tv-tas,uit welk land komt de avocado?");
    }
  }

You can store a count in Inline editor.您可以将计数存储在内联编辑器中。 There are two options for storing data and you can choose based on whether you want to save data within a conversation or across conversations.有两种存储数据的选项,您可以根据是要在对话中还是跨对话保存数据来选择。 If it is within conversation (your game score for current session) use conversationToken .如果它在对话中(您当前会话的游戏得分),请使用conversationToken Example:例子:

let conv = agent.conv(); // create an instance
conv.data.pointspt1 = 0;
conv.data.pointsp2 = 1;
const total = conv.data.pointspt1 + conv.data.pointspt2;
agent.add(`Your total score is ${total}`);
// If you want to save data across conversations
conv.user.storage.pointspt1 = 0; // This works only for verified users

Refer to the following link for more informations: Save data in conversation有关详细信息,请参阅以下链接: 在对话中保存数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM