Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 为什么';设置一个全局变量?_Node.js_Firebase - Fatal编程技术网

Node.js 为什么';设置一个全局变量?

Node.js 为什么';设置一个全局变量?,node.js,firebase,Node.js,Firebase,我有一个大型程序,可以在Dialogflow中很好地为GA home speakers说话,但是添加express html支持会使测试情况显示通过两个函数说话会使别名变为变量。一个很小的例子很容易就说明了这一点,我想修复它,并知道为什么is也会做坏事 因此,添加,设置为零,并查看为每个变量显示一个维护值,不幸的是,该值是两个值。好像有一个 var HtmlCounter=0; var SpeakerCounter=0 显然,欲望是有一种价值,而不是两种。它的别名是“或什么” 我试过: ()生成

我有一个大型程序,可以在Dialogflow中很好地为GA home speakers说话,但是添加express html支持会使测试情况显示通过两个函数说话会使别名变为变量。一个很小的例子很容易就说明了这一点,我想修复它,并知道为什么is也会做坏事

因此,添加,设置为零,并查看为每个变量显示一个维护值,不幸的是,该值是两个值。好像有一个 var HtmlCounter=0; var SpeakerCounter=0

显然,欲望是有一种价值,而不是两种。它的别名是“或什么”

我试过: ()生成一个var globals={},然后附加别名变量。 ()更改变量使用的嵌套,试图使Dialogflow感觉它拥有的变量更多一些

'use strict';


// Me Daniel B Kolis
// dankolis@gmail.com

var versionNow = "03 Oct 2019 16:00";

// This is the troublesome variable
var aCounter = -1;

const functions =               require( 'firebase-functions' );
const express =                 require( 'express' );
const eapp = express();

const {WebhookClient} =         require( 'dialogflow-fulfillment' );
var bodyParser     =            require( 'body-parser' );

// Middleware
const cors =                    require( 'cors' ) ( { origin: true } );
eapp.use( cors );


// Import the service function and various response classes
const { dialogflow, actionssdk, Image, Table,   Carousel } = 
      require( 'actions-on-google' );

// Dialog flow talks to humans using google assistant
const app = dialogflow();

// Three http pages via the express package
eapp.get( '/show_counter.html', (req, res) => 
{
    let moreSeeable = "Counter is " + aCounter.toString();
    res.send( moreSeeable );
});

eapp.get( '/reset_counter.html', (req, res) => 
{
    let moreSeeable = "Acounter is this now: " + aCounter.toString() + 
                      " but right now, set to 0";
    aCounter = 0;
    res.send( moreSeeable );
});

eapp.get( '/add_counter.html', (req, res) => 
{
    let moreSeeable = "Acounter is this now: " + aCounter.toString() + 
                      " but lets add one to it";
    res.send( moreSeeable );
    aCounter = aCounter + 1;
});


// Here we are configuring express to use body-parser as middleware
eapp.use( bodyParser.urlencoded( { extended: false } ) );
eapp.use( bodyParser.json() );

// Note: This `api` must match with `/firebase.json` rewrites rule
exports.api = functions.https.onRequest( eapp );

// Start up hint if you look at logs locally or on the cloud
console.log( "VR: " + versionNow );
console.log( "First line(s) in program, sort of. Now what ?" );
console.log( "aCounter starts at: " + aCounter );

// Create I/O object for dialogs
exports.dialogflowFirebaseFulfillment = 
functions.https.onRequest((request, response) => 
{
    const agent = new WebhookClient({ request, response });

    // Left part is triggered by human speech, right is the
    // function it calls
    let intentMap = new Map();
    intentMap.set( 'addone', addOne );
    intentMap.set( 'questioncounter', questionCounter );
    intentMap.set( 'resetcounter', resetCounter );
    agent.handleRequest( intentMap );
});


// Three functions called by intents, a decode of speech spoken
function questionCounter ( agent ) 
{
    // Computers speak this
    agent.add( 'Counter is ' + aCounter.toString() );
}

function addOne( agent ) 
{
    let rightNow = aCounter;
    aCounter = aCounter + 1;
    agent.add( 'Counter is now ' + rightNow.toString() + 
               ' will be: ' + aCounter.toString() );
}

function resetCounter( agent ) 
{
    aCounter = 0;
    agent.add( 'Counter set to zero' );
}

// End of sad submission; last line of code
目标:HTML访问和通过Dialogflow从语音到语音的语音都修改一个值,一个计数器,而不是两个。希望你能完全理解它

非常感谢您的关注,
Dan Kolis

我很惊讶没有人插手此事。无论如何,这个答案可能会帮助其他人(也许是你?)

WWW调用和Dialogflow调用在云处理中生成整个EXE的不同副本。这一点一直延伸到\tmp迷你文件系统

处理范围不太清楚DF人员和WWW人员是相同的,这可能是不切实际的。。。不管它是怎样建造的


如果你认为你委派的FB程序做的事情不应该是动态的,停下来考虑一下1拷贝是否在你不摸索的具体例子中发挥作用。无论如何,这个答案可能会帮助其他人(也许是你?)

WWW调用和Dialogflow调用在云处理中生成整个EXE的不同副本。这一点一直延伸到\tmp迷你文件系统

处理范围不太清楚DF人员和WWW人员是相同的,这可能是不切实际的。。。不管它是怎样建造的


<>如果你认为你委派的FB程序做的事情不应该是动态的,停止并考虑如果你不使用的特定实例,> 1拷贝是在播放的。

即使有混淆值的问题,如果你想使用对话流来谈论设备,也可以提供WWW页面;(并有一些截获和实时),上述的有用。我真的希望有一位专家能帮助我。但是,我还没有认真使用堆栈溢出,也许我的解释不够充分…我问的问题不好,或者。。。什么?即使存在别名值问题,如果您想使用Dialogflow进行通话设备并提供WWW页面;(并有一些截获和实时),上述的有用。我真的希望有一位专家能帮助我。但是,我还没有认真使用堆栈溢出,也许我的解释不够充分…我问的问题不好,或者。。。什么?