Help me with setbit and getbit

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hello community...

    I already have a multiplayer game released: construct.net/en/free-online-games/nevess-multiplayer-pixel-42650/play

    I'm studying ways to save bandwidth as much as possible, and one thing I still don't understand is the SET and GET bit.

    It's no use me reading about them and how to use them I don't understand is how to face the idea that they are not in the multiplayer object for example:

    player.peerid("1234")

    Multiplayer.getbit(0,1) = = Jump

    Why do we write and read in system expressions and not in multiplayer... Why then don't we use variables ??

    Instead of set bit put a boolean ? I am not understanding this.

  • getbit/setbit allow you to use a single number variable as a mini-array of values. You can store up to 32 boolean values (0 and 1) in it. And then send this variable with multiplayer plugin.

    Let's say you need to send the information of which buttons on the keyboard are pressed. Normally you would need a dozen or so variables for that. But with getbit/setbit you can encode them all into a single number:

    Then once the peer receives this number, you can decode it using getbit expression. For example, to check if the space key was pressed on the remote host - getbit(keysVar, 4)=1

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you, your explanation was very well done, but it is not very easy to understand these commands.

    When I open the debug I see the variable Keysvar = 1 Nothing different from a normal variable that could be...

    Who knows, maybe one day we'll see something like...

    PEER:

    [On client update]

    On space pressed... > Multiplayer.Sendcomand("keySpace")

    HOST:

    On command received from peer("keySpace")

    Player.peerid≠MyID

    player : JUMP

  • When I open the debug I see the variable Keysvar = 1 Nothing different from a normal variable that could be...

    Because it is a normal variable. All integer numbers are made of bits and setbit/getbit expressions allow you to change individual bits in a number. Read about the binary system if you want to better understand how they work, for example:

    mathsisfun.com/binary-number-system.html

  • Thanks a lot

    Are messages lighter than bits?

    I see that you send messages don't send the data through the original path of the realtime tutorial. I found it very interesting.

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