Websocket API Collisions

Hello!

Hoping to help one of my developers with getting collisions to work with the websocket API. The way that the code is currently written, whenever we interact with a statue in our test, the collisions seem to only be set for a single tile. The game.setImpassable functions we use seem to wipe out any prior collision setting, so only the last function ends up working. We tried to match the syntax from the chopping trees example code, but we haven’t got this to work yet. Any insights are greatly appreciated!

Thank you!
Kevin

//Main code
const runSocks = () => {
  game.subscribeToEvent("playerInteracts", (data, _context) => {
    const statueID = parseInt(data.playerInteracts.objId);
    const doorID_ONE = locationToId[`${DOOR_ONE.x},${DOOR_ONE.y}`];
    const doorID_TWO = locationToId[`${DOOR_TWO.x},${DOOR_TWO.y}`];

    console.log(`Statue ${statueID} statueID was triggered by`, _context?.player?.name ?? _context.playerId);

    let statueState = game.partialMaps[MAP_ID].objects?.[statueID].normal;
    let doorOneState = game.partialMaps[MAP_ID].objects?.[doorID_ONE].normal;
    let doorTwoState = game.partialMaps[MAP_ID].objects?.[doorID_TWO].normal;

    statueState == STATUE.off? statueState = STATUE.on : statueState = STATUE.off;
    doorOneState == DOORS.close? doorOneState = DOORS.open : doorOneState = DOORS.close;

    game.engine.sendAction({
      $case: "mapSetObjects",
      mapSetObjects: {
        mapId: MAP_ID,
        objects: {
          [statueID]: {
            normal: statueState,
            highlighted: statueState,
            customState: statueState == STATUE.off? "statue-off" : "statue-on",
            _tags: [],
          },
        },
      },
    });

    game.engine.sendAction({
      $case: "mapSetObjects",
      mapSetObjects: {
        mapId: MAP_ID,
        objects: {
          [doorID_ONE]: {
            normal: doorOneState,
            highlighted: doorOneState,
            customState: doorOneState == DOORS.close? "door-close" : "door-open",
            _tags: [],
          },
        },
      },
    });

    game.engine.sendAction({
      $case: "mapSetObjects",
      mapSetObjects: {
        mapId: MAP_ID,
        objects: {
          [doorID_TWO]: {
            normal: doorOneState,
            highlighted: doorOneState,
            customState: doorOneState == DOORS.close? "door-close" : "door-open",
            _tags: [],
          },
        },
      },
    });

    if (doorOneState == DOORS.close) {
      game.setImpassable(MAP_ID, DOOR_ONE.x, DOOR_ONE.y, true);
      game.setImpassable(MAP_ID, DOOR_TWO.x, DOOR_TWO.y, true);
    } else {
      game.setImpassable(MAP_ID, DOOR_ONE.x, DOOR_ONE.y, false);
      game.setImpassable(MAP_ID, DOOR_TWO.x, DOOR_TWO.y, false);
    }

  });

Interesting… I assume it doesn’t print any helpful errors?

And if you swap the order of the setImpassables, it’s still only the second one which takes effect?

Next time you run this and the bug happens, can you post the output of game.getStats() and the current time please? So I can check out the corresponding game server logs

Hi Nate!

Yup, exactly. Even if I swap the order of the setImpassables, only the last collision gets set. Any other collisions set before the last line get wiped out as far as I can tell.

Here’s the game stats with the log times. I think it might be in UTC, but for reference it’s about 2:13 AM EST.

Thanks!
Kevin

2021-10-13T06:12:18.549289+00:00 app[web.1]: Statue 9001 statueID was triggered by Kevin
2021-10-13T06:12:18.550417+00:00 app[web.1]: {
2021-10-13T06:12:18.550419+00:00 app[web.1]:   serverURL: 'wss://game-aaai-054.gather.town/',
2021-10-13T06:12:18.550419+00:00 app[web.1]:   engine: {
2021-10-13T06:12:18.550420+00:00 app[web.1]:     connected: true,
2021-10-13T06:12:18.550420+00:00 app[web.1]:     latency: { max: -1, avg: -1, min: -1, last: -1 },
2021-10-13T06:12:18.550421+00:00 app[web.1]:     reconnects: { timeSpentDisconnectedMs: [Object], count: 0 },
2021-10-13T06:12:18.550421+00:00 app[web.1]:     errors: { count: 0 },
2021-10-13T06:12:18.550422+00:00 app[web.1]:     bufferedAmount: { max: 1469, avg: 611.3, min: -1, last: 1043 },
2021-10-13T06:12:18.550422+00:00 app[web.1]:     bytesSentSinceConnect: 5361,
2021-10-13T06:12:18.550422+00:00 app[web.1]:     bytesReceivedSinceConnect: 465321,
2021-10-13T06:12:18.550423+00:00 app[web.1]:     eventCountsSinceOpen: {
2021-10-13T06:12:18.550423+00:00 app[web.1]:       ready: 1,
2021-10-13T06:12:18.550423+00:00 app[web.1]:       spaceSetsIdMapping: 3,
2021-10-13T06:12:18.550423+00:00 app[web.1]:       playerJoins: 3,
2021-10-13T06:12:18.550424+00:00 app[web.1]:       playerMoves: 17,
2021-10-13T06:12:18.550424+00:00 app[web.1]:       playerSetsName: 4,
2021-10-13T06:12:18.550424+00:00 app[web.1]:       playerSetsAffiliation: 3,
2021-10-13T06:12:18.550424+00:00 app[web.1]:       playerSetsSprite: 3,
2021-10-13T06:12:18.550425+00:00 app[web.1]:       playerGhosts: 3,
2021-10-13T06:12:18.550425+00:00 app[web.1]:       playerSpotlights: 3,
2021-10-13T06:12:18.550425+00:00 app[web.1]:       playerSetsEmote: 3,
2021-10-13T06:12:18.550425+00:00 app[web.1]:       playerSetsWorkCondition: 3,
2021-10-13T06:12:18.550425+00:00 app[web.1]:       playerSetsLastActive: 3,
2021-10-13T06:12:18.550426+00:00 app[web.1]:       playerActivelySpeaks: 3,
2021-10-13T06:12:18.550426+00:00 app[web.1]:       playerSetsStatus: 3,
2021-10-13T06:12:18.550426+00:00 app[web.1]:       playerSetsTextStatus: 4,
2021-10-13T06:12:18.550426+00:00 app[web.1]:       playerSetsEmojiStatus: 3,
2021-10-13T06:12:18.550426+00:00 app[web.1]:       playerSetsOutfitString: 3,
2021-10-13T06:12:18.550426+00:00 app[web.1]:       playerLeavesWhisper: 3,
2021-10-13T06:12:18.550427+00:00 app[web.1]:       playerSetsIsSignedIn: 3,
2021-10-13T06:12:18.550427+00:00 app[web.1]:       playerSetsEventStatus: 3,
2021-10-13T06:12:18.550427+00:00 app[web.1]:       playerSetsInConversation: 3,
2021-10-13T06:12:18.550427+00:00 app[web.1]:       playerSetsCurrentDesk: 3,
2021-10-13T06:12:18.550427+00:00 app[web.1]:       playerSetsCurrentArea: 3,
2021-10-13T06:12:18.550427+00:00 app[web.1]:       playerSetsGoKartId: 3,
2021-10-13T06:12:18.550427+00:00 app[web.1]:       playerSetsIsAlone: 3,
2021-10-13T06:12:18.550428+00:00 app[web.1]:       mapSetDimensions: 55,
2021-10-13T06:12:18.550428+00:00 app[web.1]:       mapSetCollisions: 55,
2021-10-13T06:12:18.550428+00:00 app[web.1]:       mapSetBackgroundImagePath: 55,
2021-10-13T06:12:18.550428+00:00 app[web.1]:       mapSetSpaces: 55,
2021-10-13T06:12:18.550428+00:00 app[web.1]:       mapSetSpawns: 55,
2021-10-13T06:12:18.550428+00:00 app[web.1]:       mapSetPortals: 55,
2021-10-13T06:12:18.550429+00:00 app[web.1]:       mapSetAnnouncer: 55,
2021-10-13T06:12:18.550429+00:00 app[web.1]:       mapSetAssets: 55,
2021-10-13T06:12:18.550429+00:00 app[web.1]:       mapSetObjects: 59,
2021-10-13T06:12:18.550429+00:00 app[web.1]:       mapSetUseDrawnBG: 55,
2021-10-13T06:12:18.550429+00:00 app[web.1]:       mapSetForegroundImagePath: 35,
2021-10-13T06:12:18.550429+00:00 app[web.1]:       mapSetWalls: 17,
2021-10-13T06:12:18.550430+00:00 app[web.1]:       mapSetFloors: 17,
2021-10-13T06:12:18.550430+00:00 app[web.1]:       mapSetDescription: 3,
2021-10-13T06:12:18.550430+00:00 app[web.1]:       warn: 5,
2021-10-13T06:12:18.550430+00:00 app[web.1]:       spaceOverwrites: 1,
2021-10-13T06:12:18.550430+00:00 app[web.1]:       playerInteracts: 2,
2021-10-13T06:12:18.550430+00:00 app[web.1]:       serverHeartbeat: 1
2021-10-13T06:12:18.550431+00:00 app[web.1]:     },
2021-10-13T06:12:18.550431+00:00 app[web.1]:     closeCodeCount: {}
2021-10-13T06:12:18.550431+00:00 app[web.1]:   },
2021-10-13T06:12:18.550431+00:00 app[web.1]:   wsReadyState: 1,
2021-10-13T06:12:18.550431+00:00 app[web.1]:   timeToFirstMapDataMs: -1,
2021-10-13T06:12:18.550432+00:00 app[web.1]:   datadogRumSessionId: undefined,
2021-10-13T06:12:18.550432+00:00 app[web.1]:   gameClientAgeMs: 14369,
2021-10-13T06:12:18.550432+00:00 app[web.1]:   numPlayers: 3
2021-10-13T06:12:18.550432+00:00 app[web.1]: }
2021-10-13T06:12:18.550445+00:00 app[web.1]: No teleporting from Statue 9001

Ok thanks, that was super helpful. The issue is actually that one of your objects is undefined (which really shouldn’t show up here but does for historical reasons). quick fix is to just use the api to delete it

I’m going to add a patch to the game server to just ignore undefined objects, and we’ve already added something that would return this error to you so you know something is bonked next time
Both of those should come out in next monday’s release

1 Like

Fantastic! That makes sense and I just checked and it seems like it’s already been fixed! Thanks Nate! :+1:

Hmm, I think the collisions are broken again for me. I do see the new error code in my logs, but it seems to be an error I can’t fix.

2021-10-21T05:48:30.486529+00:00 app[web.1]: [error from gs] 500: Cannot read property ‘highlighted’ of undefined

Looking at the entire object list for everything in the space, there’s a password door object that seems to be the cause.

> '2': {
> 2021-10-18T19:40:17.833533+00:00 app[web.1]:       _tags: [],
> 2021-10-18T19:40:17.833534+00:00 app[web.1]:       normal: 'https://cdn.gather.town/v0/b/gather-town.appspot.com/o/uploads%2FoxrhEtb3sV7VutbQ%2Fassets%2Fa207c9c3-61f1-45ed-9175-227d5747b547?alt=media&token=60a37549-3097-48cd-86fa-34715f37a610',
> 2021-10-18T19:40:17.833534+00:00 app[web.1]:       highlighted: 'https://cdn.gather.town/v0/b/gather-town.appspot.com/o/uploads%2FoxrhEtb3sV7VutbQ%2Fassets%2Fe599618b-64b1-4778-ab02-8a81389ef8e0?alt=media&token=5e2eb610-9ecd-47ea-9bd8-b650fbcb4f5e',
> 2021-10-18T19:40:17.833534+00:00 app[web.1]:       type: 7,
> 2021-10-18T19:40:17.833535+00:00 app[web.1]:       width: 1,
> 2021-10-18T19:40:17.833535+00:00 app[web.1]:       height: 1,
> 2021-10-18T19:40:17.833535+00:00 app[web.1]:       id: 'password-door_2b5f2bac-850e-443c-afbd-3f2ece65b698'
> 2021-10-18T19:40:17.833535+00:00 app[web.1]:     }

This object was created with the Gather Extension for password doors. I used the API to delete the doors, since I was unable to delete it with the mapmaker. However, I still got the error. Originally it was telling me that there was a wireframing issue and that an undefined object was missing coordinates. After deleting the object from my space, the coordinate and wireframe errors went away, but I still have the 500 error when I interact with objects. I believe this still has to do with the Extension Password doors.

I disabled all extensions and even deleted the room where the object was placed, and I’m still getting the error. My collisions are still broken as well.

Should I create a new space to test out my websocket code, or is there a way to fix this?

Thanks!
Kevin

This is really spooky, sorry – will try to debug the several issues here asap but in the meantime yeah maybe just start fresh. Will keep posting here as I figure things out

Also, what’s the spaceId? Feel free to DM if you don’t want to share it publicly

Perfect! Just DMed you! Thanks!

Hi there,

Just letting you know we haven’t dropped this thread, just really busy over here! Which map inside of this space is the statue in? I dropped by to take a look; do you have a minimal example I could copy and run to try it out? I’m going to try to make a test extension to replicate these issues, but I may not be able to given that it seems related the contents of a specific map. More details would be helpful!

Warmly,

Evelyn

Hi Evelyn!

No worries at all! I know Nate was working on something critical this morning, and I am always happy to see prod platform stuff worked on first!

I actually ended up creating a new space to see if the issue would go away, but it seems to have persisted. I’ll dm you the new Space URL, the raw code (index.js and config.js), and the most recent log where I’m seeing issues that crash my Heroku server (which causes the room to be empty if you visit and nothing is there). Let me know if you need anything else that would be helpful to troubleshoot.

Thank you!
Kevin

Hey Kevin,

Apologies for this taking so long. Evelyn is out of the office for a little bit so I’m trying to take a look at things now and was wondering if you could DM me everything you sent to Evelyn and anything else that you’ve run into in the meantime.

Best,
Eli

Hi Eli!

No worries! Thanks for taking a look at this for me! Evelyn helped me a bunch before she was out of office, but I am still running into a few odd things that I’m sure I’m not doing properly. I’ll DM you what I’m working on now.

Thanks!
Kevin

Also, last night we fixed a bug with portals and collisions that you were probably running into. I think the door thing is a separate issue, so still looking into that.

Sorry for the delays!