[SOLVED] How to make it so i can change game objects in a non playcanvas function?

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.

1 Like

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

yes i forgot to type that in. But it is correct in the right code.

i tried that but for some reason it also does not work. I still get an undefined error.

Ahhhh im soooo stupid. setpassword label is a function. the element was called password label. Its fine. That works thank you.