首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Bixby中防止重复的动作执行?

如何在Bixby中防止重复的动作执行?
EN

Stack Overflow用户
提问于 2019-05-20 20:08:22
回答 1查看 80关注 0票数 1

我想实现一个胶囊,如果用户提供了计算所需的完整输入,则执行计算;如果用户没有提供第一个请求的完整输入,则要求用户提供必要的输入。如果用户提供完整的请求,一切都会正常工作。如果用户没有提供完整的请求,但Bixby需要更多信息,我会遇到一些奇怪的行为,其中计算被多次调用,Bixby从另一个计算的结果中获取计算所需的信息,如调试图中所示。

为了更容易地演示我的问题,我扩展了骰子样本胶囊capsule-sample-dice,并在RollResultConcept中添加了numSidesnumDice,这样我就可以访问结果中的骰子和边数。RollResult.model.bxb现在看起来像这样:

structure (RollResultConcept) {
  description (The result object produced by the RollDice action.)
  property (sum) {
    type (SumConcept)
    min (Required)
    max (One)
  }
  property (roll) {
    description (The list of results for each dice roll.)
    type (RollConcept)
    min (Required)
    max (Many)
  }
  // The two properties below have been added
  property (numSides) {
    description (The number of sides that the dice of this roll have.)
    type (NumSidesConcept)
    min (Required)
    max (One)
  }
  property (numDice) {
    description (The number of dice in this roll.)
    type (NumDiceConcept)
    min (Required)
    max (One)
  }
}

我还在RollResult.view.bxb中添加了single-line,以便在掷完一轮后向用户显示边和骰子的数量。RollResult.view.bxb:

 result-view {
   match {
     RollResultConcept (rollResult)
   }

   render {
     layout {
       section {
         content {
           single-line {
             text {
               style (Detail_M)
               value ("Sum: #{value(rollResult.sum)}")
             }
           }
           single-line {
             text {
               style (Detail_M)
               value ("Rolls: #{value(rollResult.roll)}")
             }
           }
           // The two single-line below have been added
           single-line {
             text {
               style (Detail_M)
               value ("Dice: #{value(rollResult.numDice)}")
             }
           }
           single-line {
             text {
               style (Detail_M)
               value ("Sides: #{value(rollResult.numSides)}")
             }
           }
         }
       }
     }
   }
 }

编辑:我忘记添加我在RollDice.js中更改的代码,如下所示: RollDice.js

// RollDice
// Rolls a dice given a number of sides and a number of dice

// Main entry point
module.exports.function = function rollDice(numDice, numSides) {

  var sum = 0;
  var result = [];

  for (var i = 0; i < numDice; i++) {
    var roll = Math.ceil(Math.random() * numSides);
    result.push(roll);
    sum += roll;
  }

  // RollResult
  return {
    sum: sum,           // required Sum
    roll: result,       // required list Roll
    numSides: numSides, // required for numSides
    numDice: numDice    // required for numDice
  }
}

结束编辑

在模拟器中,我现在运行以下查询

intent {
  goal: RollDice
  value: NumDiceConcept(2)
}

它缺少所需的NumSidesConcept

调试视图显示了以下图形,其中缺少NumSidesConcept (正如预期的那样)。

现在,我在模拟器中运行以下查询

intent {
  goal: RollDice
  value: NumDiceConcept(2)
  value: NumSidesConcept(6)
}

这将在Debug视图中生成以下图形:

在我看来,为了得到结果,这个计算被做了两次。我已经尝试将feature { transient }提供给模型,但这并没有改变任何事情。有人能告诉我这里发生了什么吗?我是否不允许在输出中使用相同的原语模型,因为Bixby在尝试执行操作时会使用它们?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-21 05:09:38

我尝试像您一样修改代码,但无法(成功)运行intent。

开始编辑

我在RollDice.js中添加了额外的行,并且能够看到您正在查看的计划。

双重执行的原因是您连续运行了意图,Bixby从第二个意图中获得了您在第一个意图中没有指定的NumSidesConcept的值,并执行了第一个意图。

您可以通过在每个意图中为NumSidesConcept和NumDiceConcept提供一组不同的值来验证上面的内容。

如果你在这两个意图之间给了足够的时间,那么结果就会不同。在您的场景中,第一个意图是等待NumSidesConcept可用,一旦规划者找到它(根据第二个意图的结果),执行就完成了。

怎样才能避免这种情况呢?确保每个输入都有一个input-view,这样Bixby就可以提示用户输入没有通过NL (或对齐NL)的任何值。

结束编辑

这是另一种方法,它不需要更改RollResultConcept,并且将根据您的期望(访问result-view中的骰子和边数)来工作。

 result-view {
  match: RollResultConcept (rollResult) {
    from-output: RollDice(action)
  }


   render {
     layout {
       section {
         content {
           single-line {
             text {
               style (Detail_M)
               value ("Sum: #{value(rollResult.sum)}")
             }
           }
           single-line {
             text {
               style (Detail_M)
               value ("Rolls: #{value(rollResult.roll)}")
             }
           }
           // The two single-line below have been added
           single-line {
             text {
               style (Detail_M)
               value ("Dice: #{value(action.numDice)}")
             }
           }
           single-line {
             text {
               style (Detail_M)
               value ("Sides: #{value(action.numSides)}")
             }
           }
         }
       }
     }
   }
 }

试一试,让我们知道它是否有效!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56220729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档