aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-01-24 18:15:09 -0500
committerHolden Rohrer <hr@hrhr.dev>2020-01-24 18:15:09 -0500
commitfdac79c026a2f6a321a1a3846c2f331bede6af02 (patch)
treeabc741d62cbc87e69ace01dd2dad24a12853b616 /examples
parent496ee8200fa540663fafd7092f8ca5cce65a0bef (diff)
jarvis changed in preparation for search refactor
Diffstat (limited to 'examples')
-rw-r--r--examples/jarvis.js11
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);
}
});