更新全局变量是否有限制? google 电报机器人的应用程序脚本
Is there a limit to update the global variable? google app script to telegram bot
目前我的代码能够 运行 直到 currentstep = '2'。我已经更新了我的调查(数据)中的 currentstep = '3',它将能够执行我的 xD(数据)。但是,代码不会更新为“3”到 运行。
function check_command(data){
var text = data.message.text;
if(text == "/start" || text == "/start"){
currentstep = '1';
return;
}
if (text == "/survey" || text == "/survey"){
currentstep = '2';
return;
}
return;
}
function process_loop(data){
if(currentstep == "1"){
start(data);
return;
}
if(currentstep == "2"){
survey(data);
return;
}
if(currentstep == "3"){
xD(data);
return;
}
}
function doPost(e){
var data = JSON.parse(e.postData.contents);
check_command(data);
process_loop(data);
}
根据您的代码,您提到要在 survey(data)
中设置 currentstep = '3'
。
每当您收到 doPost() 时,您将在 check_command(data)
中将 currentstep
设置为 1 或 2。然后它将调用 process_loop(data)
。如果currentstep初始为2,那么在survey(data)
中会被设置为3。但是,由于您包含 return
语句,它将退出 process_loop(data)
。因此xD(data)
不会被执行。
您可以决定是仅删除 (currentstep == "2")
中的 return
语句还是在每个条件中都删除它们。
目前我的代码能够 运行 直到 currentstep = '2'。我已经更新了我的调查(数据)中的 currentstep = '3',它将能够执行我的 xD(数据)。但是,代码不会更新为“3”到 运行。
function check_command(data){
var text = data.message.text;
if(text == "/start" || text == "/start"){
currentstep = '1';
return;
}
if (text == "/survey" || text == "/survey"){
currentstep = '2';
return;
}
return;
}
function process_loop(data){
if(currentstep == "1"){
start(data);
return;
}
if(currentstep == "2"){
survey(data);
return;
}
if(currentstep == "3"){
xD(data);
return;
}
}
function doPost(e){
var data = JSON.parse(e.postData.contents);
check_command(data);
process_loop(data);
}
根据您的代码,您提到要在 survey(data)
中设置 currentstep = '3'
。
每当您收到 doPost() 时,您将在 check_command(data)
中将 currentstep
设置为 1 或 2。然后它将调用 process_loop(data)
。如果currentstep初始为2,那么在survey(data)
中会被设置为3。但是,由于您包含 return
语句,它将退出 process_loop(data)
。因此xD(data)
不会被执行。
您可以决定是仅删除 (currentstep == "2")
中的 return
语句还是在每个条件中都删除它们。