[Suggestion] Auto convert numbers to strings

Discussion and feedback on Construct 2

Post » Mon Jul 14, 2014 5:56 pm

Hi. When I tried to send numbers via a Multiplayer.SendMessage action or when I try to GoToLayout.ByName and use a integer/number variable nothing happens. I have to add "str(VARNAME)" to make it work. Do you think it would be possible and/or better to auto convert such numbers to a string if a string is needed by the action and vice versa? If a number is needed a string could become a number so the math or other code works.

Some coding environments I used in the past have such a system and made it very easy to use variables with the "wrong" format and it can save you some time.
Or are there any disadvantages or problems with this?
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
56
S
16
G
6
Posts: 743
Reputation: 9,310

Post » Mon Jul 14, 2014 6:27 pm

Having experience creating (multiplayer) plugins I can say that certain input expressions need to be explicitly in a certain format (string,int,etc) so as not to break the functionality of the object. The plugin parameter types are a predefined by the creator of the plugin as to what it will accept "paramAny, paramNumber, paramString" usually for a reason. In the case of multiplayer message (where i have a lot of experience) the problem you would have is that if you try to send a number it will always have to be converted to a string before being sent by the plugin. So when its received on the other end you will get a string in stead of the int you sent any way. You would have to convert it back to an int on the other end regardless.

The best method for maintain data types for string transmission is JSON. With out any 3rd party plugins the easiest way to pass data is to load it into a dictionary, send the dictionary AsJSON and then when the peer receives it that load that JSON back into a dictionary and act on the data. By doing it this way you can maintain data types and can send complex instructions all in a single transmission. I can say with certainty that its just as fast and completely reliable as i do all of my multiplayer data transmission in this format.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Mon Jul 14, 2014 9:46 pm

Here you go
var = "string" & 1337

C2 uses "&" for concatenation rather than "+"
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,028


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 23 guests