• Question
  • Can someone help explain key values to me?

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

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");}
}

Thanks for your help!

L
Last Chat :(
See ya round, people.
Aug 16, 2024
T
t43rew t34t3t45ret 45 e trsdyrt
wt rtret
Aug 14, 2024
general
Goodbye Gamelab Forum.
Aug 12, 2024
Not CDO chat
yes
Jul 25, 2024

Chat

Welcome to the Chat!

Please select a channel or DM on the left.
;