我想实现一个胶囊,如果用户提供了计算所需的完整输入,则执行计算;如果用户没有提供第一个请求的完整输入,则要求用户提供必要的输入。如果用户提供完整的请求,一切都会正常工作。如果用户没有提供完整的请求,但Bixby需要更多信息,我会遇到一些奇怪的行为,其中计算被多次调用,Bixby从另一个计算的结果中获取计算所需的信息,如调试图中所示。
为了更容易地演示我的问题,我扩展了骰子样本胶囊capsule-sample-dice,并在RollResultConcept
中添加了numSides
和numDice
,这样我就可以访问结果中的骰子和边数。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在尝试执行操作时会使用它们?
https://stackoverflow.com/questions/56220729
复制相似问题