Granted
September 5, 2022, 2:45am
#1
Im trying to run a function that changes text but i cant seem to do it in a function that has no playcanvas api. is there a way i can get it to work with an external function?
Login.prototype.initialize = function() {
this.setpassword.button.on("click",function(event){
setCookie("password",prompt("Password"),1);
if(getCookie("password")!=""){
this.setpasswo.element.text=CryptoJS.SHA1(getCookie("password"));
}
});
this.setusername.button.on("click",function(event){
setCookie("username",prompt("Username"),1);
});
};
Hi @Granted ! I guess you get an error on line 5 of the code above? Are you sure this.setpasswo
should not be this.setpassword
? Please check also the topic below.
Can someone explain why we can’t use this inside a timeout directly?
var that = this;
setTimeout(function(){
that.stone.reparent(this.entity);
that.stone.enabled = false;
}, 1000);
1 Like
yaustar
September 5, 2022, 8:52am
#3
On top of Albertos advice, PlayCanvas events allow you to pass the scope of the object as the third parameter. So it should look like this:
Login.prototype.initialize = function() {
this.setpassword.button.on("click",function(event){
setCookie("password",prompt("Password"),1);
if(getCookie("password")!=""){
this.setpassword.element.text=CryptoJS.SHA1(getCookie("password"));
}
}, this);
this.setusername.button.on("click",function(event){
setCookie("username",prompt("Username"),1);
}, this);
};
1 Like
Granted
September 6, 2022, 10:54am
#4
yes i forgot to type that in. But it is correct in the right code.
Granted
September 6, 2022, 10:54am
#5
i tried that but for some reason it also does not work. I still get an undefined error.
Granted
September 6, 2022, 10:59am
#6
Ahhhh im soooo stupid. setpassword label is a function. the element was called password label. Its fine. That works thank you.