Starting to feel a limitation of Lens Studio!
Hey guys, I am starting to run in to limitations that are preventing me from creating some amazing stuff
trying to build something I can scale up on, not seeing or maybe I have mislooked/misread but no way for a "tap" to increment a var as scope is local and not able to set global vars? so looking at using hashtable below is my prototype code
var HashTable = function (size, hash) {
if(hash) this.hash = hash;
this.table = new Array(size);
}
HashTable.prototype = {
insert: function(key,val) {
var hash = this.hash(key);
if (!this.table[hash]) this.table[hash] = {};
this.table[hash][key] = val;
},
has: function(key) {
return !!this.table[this.hash(key)][key]
},
percentFull: function() { // TODO: use this.has for cohesion
var filled = this.table.filter( function(a){return !!a} );
return (filled.length / this.table.length) *100;
},
hash: function(key) {return key % this.table.length}
}
var hashTable = new HashTable(10);
hashTable.insert(2, 'two');
hashTable.insert(12, 'twelve');
hashTable.insert(13, 'thirteen');
print(hashTable.table);
print(hashTable.has(13)); // -> true
print(hashTable.has(23)); // -> false
print(hashTable.percentFull() + '%'); // -> 20%
if anyone from LensStudio snap wants to talk about what I am trying to achieve happy to discuss
Hi Patrick, great question!
You do actually have access to global scope. Search "The Global Scope" in this documentation page:
https://lensstudio.snapchat.com/guides/scripting/scripting-overview/
Additionally, you can store any variable on the script component. For example, the following script can be bound to the "Tapped" event and each time you tap, it prints out the number of times you've tapped.
Finally, you can also use a different script component to store a variable that you can access elsewhere. An example here is that you can have a controller that stores the number of taps and an input script that tells the controller when a tap has happened. To do this, you can use script.api. Check out "The API Property" section in the same scripting guide.
https://lensstudio.snapchat.com/guides/scripting/scripting-overview/
so simple.. thank you once again Travis!
from your experience do you think script.numTaps will work over hash table for scoring in AR game experience
score would have to be sprite update based on script.numTaps, but I feel hashtable allows for more scaleable approach e.g. collect red coins to get Reward.
I like to start simple and then refactor when it feels like it's getting too complex. But yah, your Hash Table approach should work nicely, save you some future refactoring and you can throw it in global if you want it easily accessible every where.
Yes I agree with your concerns I am also on lens studio from many years but never faced any issue regarding it as you can seehere some of my lenses that I created.
I like to start simple and then refactor when it feels like it's getting too complex. But yeah, your Hash Table approach should work nicely, save you some future refactoring and you can throw it in global if you want it easily accessible everywhere. Yes, I agree with your concerns. I am also on lens studio for many years but never faced any issue regarding it as you can see here some of the lenses that I created.
I like to start simple and then refactor when it feels like it's getting too complex. from your experience do you think script? numerals will work over the hash table for scoring in AR game experience. I am also on lens studio for many years but never faced any issue regarding it as you can see here some of the lenses that I created.
As the project becomes more complex, I like to refactor it. How about scripting? In AR game experience, numbers are worked over the hash table. It has been years since I have used lens studio, but I have never encountered any problems as you can see here.
from your experience do you think script.numerals will work over the hash table for scoring in AR game experience
score would have to be sprite update based on the script.numTaps, but I feel hashtable allows for a more scaleable approach e.g. collect red coins to get Reward.
This is exactly the same kind of lens idea that I used some weeks ago you can seehere hopefully it will be as exciting as you mentioned here.