我正在使用内联编辑器在对话流中进行多人测验。目前,我已经完成了第 1 轮和第 2 轮的工作,但还没有计分。
所以也许这很愚蠢,但我想'哦,我会制作一个 var 并在其中存储一个计数。每当一个函数有一个很好的答案时,de count 都会做 ++ 等等。”
我制作了一个包含 2 个问题的片段,以便您了解我的问题。我读过很多关于哦,你必须将它存储在用户存储中,但我不明白如何。已经阅读了 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");
}
我希望当我将函数称为“总分”时。它会根据最佳答案显示哪个玩家赢得了回合。
编辑,尝试用户存储:
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?");
}
}