GitHub | Documentation | Become a Patron

How to use @nosync in nodejs



  • Hi Guys

    I am using Colyseus on javascript and saw in the document that you can add @nosync to a variable that you want private. I tried this and got an error in nodejs saying does not know @ symbol. I was wondering how you would do it and if any of you have already encountered and solved this problem ?

    Thank you so much

    Tyrus Shan


  • administrators

    Hey @tyrus-shan,

    If you're not using TypeScript, you can use nosync as a regular function, like this:

    const nosync = require("colyseus").nosync;
    
    class YourState {
      constructor () {
        this.privateProperty = "I won't be synched";
        nosync(this, 'privateProperty');
      }
    }
    

    Hope this helps



  • Hi @endel
    Thank you so much for the quick response