How do I Construct 2 like a Pro? Values Question

0 favourites
  • 5 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Let's keep it simple,

    I have two values,

    Value X and Value Y

    Value X and Y can both be any number possible so we don't know how long the value will be.

    X= ? Y = ?

    Now we want to send Value X and Value Y as a message to the host in the multiplayer plugin.

    So I ask you, How do we figure out where Value X ends and where Value Y begins?

  • Separate them with a token ("," generally works well) when composing the message and use tokenat() on the host side to parse out the pieces.

    https://www.scirra.com/manual/126/system-expressions

  • Could you possibly show me how you would separate them two values?

    I can send the message but I keep having a problem with converting strings to values.

    So it's kinda like it gets sent but then you end up with multiplayer message so the tokenat thing isn't really working out how I would of liked it to.

  • So peer sends message "2.13123,32.1234"

    Host receives the message, saves it to a variable (or array or dictionary or instance variable ect.)

    On peer message - set SavedMessage to Multipayer.Message

    To get the first value as a float, use float(tokenat(SavedMessage,0,",")) - returns 2.13123 as a value.

    To get the second value, use float(tokenat(SavedMessage,1,",")) - returns 32.1234 as a value

    You can use tokenat directly on Multiplayer.Message itself instead of saving it to an intermediate storage variable first if you don't need the value to persist.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • First off thank you so much oosyrag for all your help.

    This is what I got so far,

    FROM PEER

    On left mouse button down.

    Send message to host str(value1|value2)

    ON HOST SIDE

    on peer message > set global value to multiplayer message.

    set text to global value

    Error prints out " 1 "

    But should so 1 = value 1 5 = value 2

    What's wrong with this?

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