Why getInt is doesn't work ?
var store = global.persistentStorageSystem.store;
var scoreKey = "totalScore";
var currentGameScore = store.getInt(scoreKey);
print( "Loaded score: " + currentGameScore);
function onTap(eventData)
{
print("tapped");
currentGameScore += 1;
// Store the current score in persistent storage
store.putInt(scoreKey, currentGameScore);
// Print the current score
print("Current score: " + currentGameScore);
}
var tapEvent =!tapEvent ? script.createEvent("TapEvent").bind(onTap) : tapEvent;
19:22:25 TypeError: cannot read property 'getInt' of undefined
at [anon] (btn2:6) preventsyield
Hi Алексей,
That's very strange, I tried running the script in the latest version (2.0.0.2) and it's working for me with no errors.
Can you let me know what version of Studio you are using, and what operating system? Also, are there any other scripts in your project that could be interfering with this one? Does it occur in an empty project too?
Hope we can figure this out! The code looks fine and shouldn't cause any problems.
Thanks,
Jacob
1.7+, win10 , nope, yep
The PersistentStorageSystem was added in release 2.0 so it won't be available in version 1.7. Can you try in the latest version and see if that fixes it?
version 2.0+ freeze after one minute of work.
Hey Алексей,
Sorry to hear about the freezing issue. If you can, please file a report if you haven't already and we can try to get that issue fixed.
PersistentStorageSystem won't work in Lens Studio 1.7, but as long as your Snapchat app is up to date you should be able to push to device and test your lens there.
You can also adjust your script like this so that it will use a fake version of PersistentStorageSystem if it's not available, to make development easier in Lens Studio:
Jacob ) hi again!
can you tell me what is wrong here?
My counter show me 1 always. And console show me some strange.
It seems that is count down to 1
"
12:06:31 Tracking restarted
12:06:31 Loaded score: 0
12:06:31 tapped
12:06:31 Current score: 3
12:06:31 tapped
12:06:31 Current score: 2
12:06:31 tapped
12:06:31 Current score: 1
12:06:35 Project backup complete
12:07:35 Project backup complete
"
// @input Component.Label tLable
var store = (global.persistentStorageSystem && global.persistentStorageSystem.store)
? global.persistentStorageSystem.store
: function(){
var storage = {};
return {
getInt: function(key) { return storage[key] || 0; },
putInt: function(key, value) { storage[key] = value; },
};
}();
var scoreKey = "totalScore";
var currentGameScore = store.getInt(scoreKey);
print( "Loaded score: " + currentGameScore);
function onTap(eventData)
{
print("tapped");
currentGameScore += 1;
// Store the current score in persistent storage
store.putInt(scoreKey, currentGameScore);
// Print the current score
print("Current score: " + currentGameScore);
script.tLable.text =''+currentGameScore;
}
var tapEvent =!tapEvent ? script.createEvent("TapEvent").bind(onTap) : tapEvent;
Hi Алексей,
It looks like maybe you set your script to run on "Tapped" instead of "Initialized" in the ScriptComponent?
You want the script to run only once (on Initialized) so it can set everything up once. The script is already creating a "Tapped" event, so if it runs every time a tap occurs it's always resetting the score and fighting with itself.
Let me know if that fixes your problem!
Jacob
Thank you Jacob it is work great! You really help me with this issue!