[SOLVED] How can I set the unique variables for cloned entity?

Hello,
I want to set the unique variables for each cloned entities.
But, the variable is copyed to all of cloned entities.
How can I set the unique variables for each cloned entity?

i.e.

ROOT’s main.js

for(var i=0; i<100; i++){
  var e = ENTITY.clone();
  e.script.JS.setNum(i);
  aPooledENTITY.push(e);
  app.root.addChild(e);
}

console.log('aPooledENTITY[13]:myNum:'+aPooledENTITY[13].script.JS.checkNum()+', aPooledENTITY[14]:myNum:'+aPooledENTITY[14].script.JS.checkNum());

aPooledENTITY[13].script.JS.setNum(0);//set 0 to 13 in aPooledENTITY.

console.log('aPooledENTITY[13]:myNum:'+aPooledENTITY[13].script.JS.checkNum()+', aPooledENTITY[14]:myNum:'+aPooledENTITY[14].script.JS.checkNum());

ENTITY’s JS.js

ENTITY.prototype = {
  initialize: function () {
  var self = this;
  var myNum;          
},

setNum: function(NUM){
  myNum =NUM;
},

checkNum: function(){
  return myNum;
},

-> result

aPooledENTITY[13]:myNum:99, aPooledENTITY[14]:myNum:99
aPooledENTITY[13]:myNum:0, aPooledENTITY[14]:myNum:0

->my demand

aPooledENTITY[13]:myNum:13, aPooledENTITY[14]:myNum:14
aPooledENTITY[13]:myNum:0, aPooledENTITY[14]:myNum:14

Thanks.

You need to use this.myNum as your entity variable. You are currently using a global variable myNum in setNum and checkNum.

Try something like this:

Entity.prototype = {
    initialize: function () {
        this.myNum = 0;
    },

    setNum: function (num) { 
        this.myNum = num; 
    },

    checkNum: function () { 
        return this.myNum; 
    }
};

Thank you, dave.
I made it!
Now I understand the SCOPE of PlayCanvas (just a litte).

Thanks a lot!