diff options
-rw-r--r-- | examples/jarvis.js | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js index 31a3443..79f0ca6 100644 --- a/examples/jarvis.js +++ b/examples/jarvis.js @@ -30,6 +30,7 @@ class MetaSocket extends Socket{ self.on('init',(send)=>{ self.sender = send; }); + Search.call(this); } } var main = new MetaSocket('testworld'); @@ -110,19 +111,17 @@ function protectArea(send, tiles, locs, id, space, ctrl){ var search = new Space(); search.adhoc('jarvis'); // The search space is the word jarvis, so whenever that's caught, a relevant function can be called. -var read = new Search(search); +var read = new Search(); +read.match(search, respond); var expire = {}; main.on('fallback', (send, tiles, locs) => { // tries to detect the prompt ('jarvis') and calls respond if found. - for (let i=0; i<locs.length; i++){ - let loc = locs[i]; + for (let loc of locs){ if (read.has(loc)){ clearTimeout(expire[loc]); - delete expire[loc]; read.del(loc); } - let results = read.add(loc, tiles[loc]); - if (results.length > 0) respond(results, send); + read.add(loc, tiles[loc]); expire[loc] = setTimeout(() => {read.del(loc); delete expire[loc];}, 30000); } }); |