在Photon Javascript SDK上有Actor类。
var Actor = (function() {
function Actor(name, actorNr, isLocal) { //constructor
this.name = name;
this.actorNr = actorNr;
this.isLocal = isLocal;
this.customProperties = {};
this.suspended = false;
}
...
}
它具有customProperties(Object)属性。当我尝试获取整个对象时,它会起作用:
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
}
当我 尝试从这个对象中获取特定的值我在任何 情况。
console.log(actor.customProperties["avatar"])
console.log(actor.customProperties.avatar)
console.log(actor.customProperties[4])
所有这些方法都返回undefined。 对这个问题有什么想法吗?
答案 0 :(得分:0)
我注意到
中各行的末尾没有逗号console.log(actor.customProperties)
输出。您确定customProperties是有效的JS对象而不是字符串吗?
答案 1 :(得分:0)
我只需要设置超时时间。演员属性尚未初始化。 Problen解决了。