Why can there only be 1 AJAX or WebSocket object at a time?

0 favourites
  • 4 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I was attempting to use the built-in AJAX and WebSocket object types to connect a game simultaneously to multiple livestreaming sites' chats and notification systems (Twitch's chats and PubSub System, Hitbox, YouTube live comments mid-broadcast, and Discord) to allow for interactivity by reading sent messages from all platforms (i.e.- the way an IRC chat bot normally works by reading !commands), but eventually discovered that only a single object of each type of plugin can be added to a project at a time.

    Is there any particular reason for this? I can figure out ways to circumvent the limitation for an AJAX-type object using global variables and setting up a pseudo function queue at the loss of speed, but ideally I'd like to be able to keep multiple concurrent WebSocket connections without having to close one and open another periodically as it appears one would have to do.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • AJAX can support multiple simultaneous requests via tags, but no ideas for WebSocket.

  • Regarding AJAX, while handling simultaneous requests is fine, it's still a bit of a hassle to have to set up several variables in order to save each request's .LastData from being lost. But yeah, it'd be nice if WebSockets created a connection ID parameter so as to enable the upkeep of multiple connections, especially when they have different behaviors (i.e.- Hitbox expects a "2::" response for its ping-pong structure as opposed to Twitch's "PONG"s, and Twitch's PubSub System expects the client to send "PING"s on its end around every two minutes instead, which is... unconventional).

  • For AJAX, recommend using dictionary object to store LastData, as you can use the AJAX.tag as your key. This allows you to create a single catch all event for any number of requests and tags, rather than having to create a specific event and condition for each tag/request.

    If you need history or logs, you can add a for each key event (with an incrementing counter) to push to an array. An additional step would be to add a comparison to check if the current key actually updated from the last pushed data in the array before pushing whatever is in the dictionary to the array (prevent duplicates/unecessary update).

    Sorry again for not having any ideas for websocket, I've never touched it and not familiar with the mechanics.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)