How do I use binaryData from websockets?

0 favourites
  • 3 posts
  • Hello,

    I'm very new to Construct. I have a working websocket server doing basic communications with a basic Construct setup. I can send text and binary from Construct to the server, and I can send text and binary from the server to Construct. What I'm trying to do is actually use the binary data I receive in Construct to change things in Construct.

    My first test is to move a sprite with binary data received from a websocket message. I'm sending a float and trying to use the value to offset the sprite Y.

    Sprite.Y + BinaryData.GetFloat32(0)

    This doesn't work- the sprite stays still. I am also sending the binary message back to the server, where it reads like this:


    I can share the Construct file if anyone is interested in seeing it.

    Does anyone have any insight for a noob? Thank you


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Without being too familiar with the binary data object, I get the feeling this is not what the binary data object is supposed to be used for.

    If you're using a number, why not just send it in a message as a number?

    You're probably not setting the buffer bounds or offset correctly, thus getting 0 returned from the expression. I'm not familiar with this either though so I can't say how it should be.

    The entire value must be within the bounds of the buffer, otherwise it returns 0. For example a 4-byte Uint32 value cannot be read from a 3-byte buffer, because all four bytes must be inside the buffer.

    Edit: See the post by Nepeo in this thread for more information.

  • Thanks very much for your response. That's exactly what I did- I stopped trying to use the binary object and just used strings (with my position data as JSON numbers). It works quite well. I'm sending from a python-based web server:

    value = { "spriteFace": [ { "X": valueX, "Y": valueY, } ] }

    where valueX and valueY are floats. Then in Construct I am parsing and using the values. I used the documentation and the "JSON" example from the start page. Great results from my first experiemnts!

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