How do I get a Number from a Character using .charCodeAt(0)

0 favourites
  • 4 posts
From the Asset Store
Jump on numbers in the proper order and reach the sun!
  • i'm using

    To send a numerical value through the "Send message" multiplayer action because it only accepts Strings

    Im trying to receive it as another player or the host or whatever like so

    But it'S giving me "Multiplayer.Message is undefined. I tried creating a variable and setting the variable to Multiplayer.Message and then using that like so

    But I'm still getting undefined.


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Browser.ExecJS does execute JavaScript.

    If your global variable is within Construct Events system, you need to use Construct's action (ie: Set global variable value to Multiplayer.message).

    It makes little sense using actual JavaScript in this instance.

    You can get an actual keycode or string from a keycode using the Keyboard plugin.

    When you send a string message, providing it a numerical value will turn it automatically in a string, so no issue on sending.

    On the receiving end, assigning a numerical value from a string can require to use the "float(Multiplayer.message)" system expression in order to "convert" it into a numerical value that could be used to assign it to a numeric global variable for example.

    So send a simpler message (loopindex is enough in this case as apparently you are doing some kind of loop).

    And when you want to assign it on reception, use the actual condition "On peer message" and in this one, assign the global variable "moltiplayertext" to float(Multiplayer.message).

    Get rid of all the useless JavaScript/Browser.ExecJS that makes things more complex than they need to be.

  • Kyatric

    If I send 4567328 as a string it uses bytes per character + more bytes for formatting with tokenat since it's impossible to expect a predefined amount of character whereas if i use String.fromCharCode it sends 넠 which is a single character so i can use the expression to get the characters by index and it uses far less bytes I think

    So i want to make this work, since it'S a multiplayer game and those kind of things are important, probably.

  • The keyboard plugin has a "StringFromKeyCode" expression that returns a single character.

    This doesn't change my answer and its logic.

    If you send a single string character then the content of Multiplayer.message is a single string character and so you don't even need a float() expression to convert it when assigning it.

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