As the more conscious of you realize by now, ENIGMA allows for C++-style declarations to be used in your projects. As you all should know, GM is very loose about its semicolons.
I asked Ism to create a script-like resource that will allow users to define their own structures and functions for use in the rest of the project. However, it is also legal in C to define structs in your code, and I don't want to alienate that as a feature.
For those who are new to C, structs are a simple data structure that lays out how chunks of memory look. They allow you to keep track of multiple things, like a named array. Instead of having, for example, a 2-Dimensional array to store x-y pairs, you could create a structure like the one featured below.
Veterans know that R3 allowed for cpp {} to handle such things. The cpp statement created a block of un-parsed code to allow users access to C++ without the parser having to check it for error, creating a workaround as well as a decent expandability. That block is no longer necessary for its old purpose; now we can choose to have it serve a new one along with it.
Say that in a create event, you want to create a structure with an X and Y pair. I don't know why you'd want to do this since you may as well just keep two arrays, but for the sake of example pretend you do.
Being used to the GM way, you say this:
struct xy {
var x;
var y;
}
direction = 0
speed = 0
That's a problem.
The parser would naively make your code look like this:
struct xy {
var x;
var y;
}
direction = 0;
speed = 0;
The above code looks correct, but in actuality, it redeclares direction as an xy structure in that piece of code. This is because the proper form for structure declaration in C is this:
struct name { int members; } instance;
I'm sure you can all imagine why that isn't good... For those who can't, it means that for the rest of that code, the word "direction" will NOT refer to the builtin variable direction. It will instead refer to an instance of your xy structure, which behaves like an instance in GML. You could say direction.x = 0; direction.y = 1;, and it would be valid. To fix this, preventing the instantiation of immediate varnames (in this case, direction), you would simply add a semicolon following the closing brace.
struct xy {
var x;
var y;
};
direction = 0;
speed = 0;
The above piece behaves as one would expect.
All this considered, we are left with three options.
- We can leave it up to the user to remember that semicolon.
I still forget that semicolon at times. It is one of the most common mistakes in C/C++.
It won't error, because direction is declared elsewhere. You'll have to figure it out yourself. - We can disallow immediate instantiation.
This means that code will be treated as if the {} had been followed by a semicolon immediately, and that you cannot declare a new structure and instantiate it with one semicolon. - We can use cpp %{ %} for such declarations, erroring if the struct isn't in one.
This is like the first option, but it will remind users to watch what they're doing. It's also pretty inconvenient, in my opinion. Whenever you want a new structure, you will have to input code similar to that below. I did like this suggestion when Miky made it, but then I couldn't make up my mind.
Code as entered for option 3:
cpp %{
struct a {
int b;
} c;
%}
Creates a structure called a, with a member called b, and instantiates it in a variable called c. You can say c.b = 0, for example.
Please read over carefully and make your choice; feel free to ask questions or justify your answer. You can change your vote (assuming SMF works like the checkbox implies it will), so don't be afraid to just place one.
Note that the script-like resource mentioned is pure C++, and so expects perfect grammar. This does not apply to it.
I also ask that you don't just randomly pick one, though picking one because your retarded friend told you to do so is fine. I figure cheating on polls is a good thing; it reflects who cares most.