GMS 2.3+ [DISCUSSION] Concat strings the easy way!

Given the changes that were made to the GML parser, I would like to know what is your opinion on YYG allowing the use of something similar to what we can see in JS and C#.

JS:
JavaScript:
var a = "foo";
var b = "bar";
var c = "damn";
var text = `Today I want ${a} with a ${b} and it was ${c} great`;
C#:
C#:
var a = "foo";
var b = "bar";
var c = "damn";
var text = $"Today I went {a} with a {b} and it was {c} great!";
right now this translates to GML as:

GML:
var a = "foo";
var b = "bar";
var c = "damn";
var text = "Today I went " + a + " with a " + b + "and it was " + c + " great!";
It would be nice to allow for such string construction on GML, what do you think?
Here are the PROS

1)
String declaration would be more compact.
2) String are less likely to have format errors (sometimes spaces as easy to forget when writing the GML way).
3) A lot of languages already provide them JS, C#, Python.
4) Wouldn't have an impact on the game performance as they can be replaced during compile time.

I know better exports and other features related to other parts of the IDE would be better appreciated but since they are already touching in the GML parser to allow for function + structs .... this would probably be a minor simple thing to add.
 

GMWolf

aka fel666
I think this is a great idea. Formatting strings is hard!
It could even be more efficient as it could optimize the allocations. Currently each + operation grows the string. But here the size of the string could be determined and only one allocation would be needed.

I would take it a step further and suggest formatting. Something like:
Code:
$"I want a {a:10d} with a {b:s}"
Using c style formatting rules.

I think it would require the string to be prefixed with a character like $ to avoid mangling existing projects.
 

Zhanghua

Member
Given the changes that were made to the GML parser, I would like to know what is your opinion on YYG allowing the use of something similar to what we can see in JS and C#.

JS:
JavaScript:
var a = "foo";
var b = "bar";
var c = "damn";
var text = `Today I want ${a} with a ${b} and it was ${c} great`;
C#:
C#:
var a = "foo";
var b = "bar";
var c = "damn";
var text = $"Today I went {a} with a {b} and it was {c} great!";
right now this translates to GML as:

GML:
var a = "foo";
var b = "bar";
var c = "damn";
var text = "Today I went " + a + " with a " + b + "and it was " + c + " great!";
It would be nice to allow for such string construction on GML, what do you think?
Here are the PROS

1)
String declaration would be more compact.
2) String are less likely to have format errors (sometimes spaces as easy to forget when writing the GML way).
3) A lot of languages already provide them JS, C#, Python.
4) Wouldn't have an impact on the game performance as they can be replaced during compile time.

I know better exports and other features related to other parts of the IDE would be better appreciated but since they are already touching in the GML parser to allow for function + structs .... this would probably be a minor simple thing to add.
The key is the macro, but the so called macro of gml is not the real macro.
 
I wondered about this. I'm glad I didn't have to ask. I'm too aggressive when I ask my questions (Not intentionally). Thanks for that dude.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
I support shorthand syntax for this in GMEdit:
the alternative (sfmt("Today I went % with a % and it was % great!", a, b, c)) isn't too bad either; some might prefer cct("Today I went ", a, " and it was"...)
 
Top