Search code examples
javascriptcoffeescriptphoton

Javascript object get value issue


There is class Actor on Photon Javascript SDK.

var Actor = (function() {
  function Actor(name, actorNr, isLocal) { //constructor
    this.name = name;
    this.actorNr = actorNr;
    this.isLocal = isLocal;
    this.customProperties = {};
    this.suspended = false;
  }
  ...
}

It has property customProperties(Object). When I try to get whole object it works:

console.log(actor.customProperties)

customProperties: {
  255: ""
  active_bonus: "0"
  avatar: "https://pp.userapi.com/c840731/v840731367/24f5a/FMmqz25jPeg.jpg"
  balance1: 8651830
  balance2: 10
  bonuses: {}
  exp: 1792250
  flag: ""
  id: 4
  rank: 0
  register_date: "3/11/2016"
  relations: (4)[-1, -1, -1, -1]
  score: 0
  state: "join"
  stats: {
    last_games: Array(5),
    games: 253,
    rank: 0,
    register_date: "3/11/2016",
    wins: 131
  }
  username: "player"
  __proto__: Object
}

When I try to get specific value from this object I get undefined in any case .

console.log(actor.customProperties["avatar"])
console.log(actor.customProperties.avatar)
console.log(actor.customProperties[4])

All of these methods return undefined. Any ideas about this issue please?


Solution

  • I just had to set timeout. Actor properties was not initialised. Problen solved.