Hello there! I am new to gather town.
I want to track player’s behavior in gather town space.
So I use following nodejs code ():
const game1 = new Game('spaceinfo', () => Promise.resolve({ apiKey: 'apikey'}));
game1.connect();
// optional but helpful callback to track when the connection status changes
game1.subscribeToConnection((connected) => console.log("game1 connected?", connected));
//#1 start
game1.subscribeToEvent("playerMoves", (data, context) => {
if(data.playerMoves.hasOwnProperty("mapId")){
unique_id = Web3Utils.utf8ToHex(context.playerId);
// console.log(unique_id);
send_event_obj ={
'1': ['gahter_town_id', context.playerId],
'2': ['map', data.playerMoves.mapId],
'3': ['gahter_town_name', context.player.name]
}
send_record_code();
}
});
//#1 end
//#2 start
game1.subscribeToEvent("playerJoins", (data, context) => {
console.log("joinjoinjoin");
unique_id = Web3Utils.utf8ToHex(context.playerId);
send_event_obj ={
'1': ['gahter_town_id',context.playerId]
}
send_record_code();
});
//#2 end
//#3 start
game1.subscribeToEvent("playerInteracts", (data, context) => {
//console.log(
// player fields may be undefined as you receive initial game info, so this is
// a convenient check if `player.name` is known yet, falling back to their ID if not
//console.log(context);
//context.player.map,
//context.playerId,
//"moved in direction",
//data
//);
itemObj =game1.getObject(data.playerInteracts.objId,context.player.map);
console.log('playerInteracts');
console.log(itemObj);
//itemMap = game.completeMaps(data.playerInteracts.mapId);
console.log(itemMap)
object_url='';
if(itemObj.obj.properties.hasOwnProperty("url")){
object_url = itemObj.obj.properties.url;
}
send_event_obj ={
'1': ['gahter_town_id', context.playerId],
'2': ['map', itemObj.obj.mapId],
'3': ['gahter_town_name', context.player.name],
'4': ['object_name',itemObj.obj._name],
'5': ['object_url', object_url]
}
send_record_code();
});
//#3 end
//#4 start
game1.subscribeToEvent("playerExits", (data, context) => {
console.log(
// player fields may be undefined as you receive initial game info, so this is
// a convenient check if `player.name` is known yet, falling back to their ID if not
//context,
context.player.map,
context.playerId,
"playerExits",
data
);
send_event_obj ={
'1': ['gahter_town_id', context.playerId],
'2': ['map', context.player.map],
'3': ['gahter_town_name', context.player.name]
}
send_record_code();
});
//#4 end
It’s working on #1, #2, #4.
But on #3, it did not pop anything on nodejs console,
so I can’t record player’s interact behavior.
This code was created by my former colleague,
and it seems worked on 2022. (Maybe? I am not really sure…)
Is there anything wrong on this code?
I think the answer maybe in this page, but I have no any idea.
Thanks!