XXelaLvl 5
- Windows
How would I see if a key value is equal to a variable?
How would I see if a key value is equal to a variable?
....
recently setkeyvalues havent been working. but heres a simple design
var coins = 0 ;
//makes the coins equal to score if score has been used before, or makes score equal to zero
getKeyValue(encodeURIComponent(getUserId())+ "score",function(score){
if(score == undefined){
setKeyValue(encodeURIComponent(getUserId())+ "score",0);
} else {
coins = score;
}
} );
function draw() {
//continously updates the key value
getKeyValue(encodeURIComponent(getUserId())+ "score",function(score){
setKeyValue(encodeURIComponent(getUserId())+ "score",coins);
} );
}
or you can just make some sort of log in system which would restore the stats from before, but i dont know how to do that
ok but im busy rn
so basically you'd have to compare it in the getKeyValue callback value or assign a variable that keeps volatile storage of that value in the program, also if you plan on testing for this every frame. just don't! it makes everything very slow and buggy, anyways i'll show two statements here one being in the callback statement while another being in a loop, ONLY UPDATING THE VALUE WHEN NECESSARY UPDATING IT CONSTANTLY WILL SLOW YOUR PROGRAM DOWN
var user = encodeURIComponent(getUserId())
var score = 0;
getKeyValue(user+"score",function(value){
if(value === undefined) {setKeyValue(user+"score", score);
} else {
score = value
}
})
function draw() {
if(score > 100) {console.log("you win");}
}
that cool
Thanks for your help!
np