I am using the Aavegotchi video tutorial to learn to use Moralis. In this tutorial, we are trying to read another player’s position and create an image on the screen for the other player. I’ve typed the code as it is in the video, but it’s giving me the following error:
main.js:124 Uncaught TypeError: Cannot read properties of undefined (reading '0x99767835b88221f59295c2a5ed77cd73f522bc2d')
at Subscription.<anonymous> (main.js:124)
at emitTwo (moralis.js:39645)
at Subscription.emit (moralis.js:39716)
at LiveQueryClient.value (moralis.js:2007)
at WebSocket.socket.onmessage (moralis.js:1799)
Here is the relevant block of code:
let user = Moralis.User.current();
let query = new Moralis.Query('PlayerPosition');
let subscription = await query.subscribe();
subscription.on('create', (plocation) =>
{
if(plocation.get("player") != user.get("ethAddress"))
{
if(competitors[plocation.get("player")] == undefined)
{
competitors[plocation.get("player")] = this.add.image(plocation.get("x"),plocation.get("y", 'dude'));
}
else
{
competitors[plocation.get("player")].x = plocation.get("x");
competitors[plocation.get("player")].y = plocation.get("y");
}
console.log("some dude moved! Get him!");
console.log(plocation.get("player"));
console.log("New X: ", plocation.get("x"));
console.log("New Y: ", plocation.get("y"));
}
})
Any ideas?