The 11th plague of Egypt
|
 |
Reply #30 Posted on: March 14, 2010, 06:23:26 am |
|
|
 Joined: Dec 2009
Posts: 274
|
GM strings are already "\\"
Local becomes necessary when you think in C++ terms
In C++ if you declare a variable inside a function (Gm users please think of a C++ function as a GML script), only that function will be able to see it. Now, since we are declaring a variable inside an event, only that event should be able to use it. If you want an object-wise variable, you should use a keyword, like the one you use global in a GM event to declare a global variable.
However, events are something that really confused me when I started C++. Even in GM, you should just use the create and the step event, since all the others are easily implementable and just mess up the code so you have to go back and forth to understand the simplest piece of code.
For example, all the keyboard and mouse events can recreated in the step event using a single line of code each.
Everybody, if you want to add a C++ feature, it's better not add it in a GM style.
|
|
« Last Edit: March 14, 2010, 06:38:57 am by The 11th plague of Egypt »
|
Logged
|
|
|
|
|
|
Josh @ Dreamland
|
 |
Reply #33 Posted on: March 14, 2010, 11:05:04 am |
|
|
Prince of all Goldfish
 Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Game_boy:
It would really blow your mind at this point if I described the difference between objects in GM and objects in C++, but basically the difference is that in C++, it's legal to say "object0 a;" instead of instance_create(object0). The implications of doing this would be difficult to explain here, so for now, disregard that.
I guess I'll start by elaborating on terms. Type: Most decent languages have some sort of data type. All languages work with data types internally. Even the really ugly one my favorite critics were just about to cite. These tell the compiler and, ultimately, the computer, what the program will be doing with a certain block of memory. Types can have different sizes and different precision, and allow different features. For example, those coming from Game Maker unknowingly work with two types: "double" (called "real") and "string" (called the same). Both of these are represented by the type "var."
Class: In Object-Oriented Programming, a class is a method of communicating to the compiler how a chunk of memory is laid out. "Structure," or "struct," is synonymous with "class" for our purposes. They can be used to lump a bunch of variables in one place, and are great for working with arrays of multiple values without going multidimensional. For example, you could store a direction and a magnitude to represent a vector in memory. In C++, that would look like this:
struct vector { double direction; double magnitude; } You could then declare and manipulate an array of them like this: vector a[100]; a[0].magnitude = 0; a[0].direction = 0; Pretty convenient, huh?
Keyword: We'll define keyword for now as words like "if" and "while," and in option 1 of this poll, "local." These keywords don't represent anything: think about it. They are used entirely to tell the compiler how to treat code (note that a type name tells the *computer* as well as the compiler how to treat something physical, namely memory). "If" tells the compiler to make the computer execute the next command conditionally. "While" tells it to keep executing it conditionally. "Local" tells ENIGMA, in one word, "don't declare this HERE; move it to the struct declaration."
By those definitions, "local" as denoted by option 1 would be a keyword, as described in that section above. "Var," however, remains ambiguous: it could do one of two things: 1) Tell Game Maker that this variable should be treated local to the script, as a keyword (Wow! that's what var does!) 2) Tell Game Maker that the following name should be declared in this scope as a block of memory to be treated as either a string or real (Wow! that's what var does too!)
So when we start adding more types, it's a matter of which is more convenient to assume.
Prototype Releases 1-3 all have var declared as a class. This makes it integrate flawlessly with C++; the behavior is very, very similar to GM. But it's not identical:
For years, the community has complained (or at least, the ones that are more aware of other languages) that Game Maker handles scopes badly. These are the people that would choose Option 1 in a pinch. However, there *are* differences in behavior, as outlined here:
if (true) { var a; a = 3.14; } show_message(string(a));
The above code would do two different things in ENIGMA and GM6. I have no information on GM7 and 8. In ENIGMA, it would print 0. In Game Maker 6, it would print 3.14.
The reason for this is ambiguous. 1) Mark didn't think it through well enough and did a bad job implementing scopes. (This would not be a first, sorry folks). 2) Mark intended for "var" only to signify that the variable was local to the code.
Option two looks *really* attractive to the common onlooker now (A certain someone was about to start typing a heated response). However, here's behavioral evidence for option 1 (assume that "a" is declared in the create event as "a = 0" and that this code is run for one step prior):
show_message(string(a)); a = 3.14; var a; a = 2;
This will print 3.14 again, meaning that Mark's parser is only aware of the point in time that the variable was declared. So, what was it? 1) Did he forgot/feel too lazy to go back over the code making "a" local throughout? 2) Did he intend for the keyword to not be retroactive? That makes it behave more like a declaration than a keyword... 3) Did he, again, really mean for it to be used as a declarator (type name) but fail to implement scopes?
Hope this helps.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
 |
Reply #35 Posted on: March 14, 2010, 11:15:05 am |
|
|
Prince of all Goldfish
 Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
For the first pair, 1 and 2 were both defining var's behavior. The second and third, we can't make that assumption... The third option specifically seems contradictory to the philosophy of a keyword. Defining where the var is coming from should be retro-active. You mentioned function declarations in Python; same principle. Most people put their vars at the top. Most Python people put their imports at the top. I believe the manual uses the word "declare" for "var," which is basically all the proof I need that Mark intended it to be like a real language... Think JavaScript scoping, again. I'll look for the page in question. Essentially, Josh @ Dreamland: he whole dilemma here is that we don't know what Mark was thinking because he implemented it badly retep998: WHO CARES WHAT HE WAS THINKING? retep998: I LIKE IT THAT WAY retep998: AND IT WORKS Josh @ Dreamland: well, if we're going to turn this into a huge genetic fallacy we may as well have our facts straight Josh @ Dreamland: haha.
|
|
« Last Edit: March 14, 2010, 11:21:30 am by Josh @ Dreamland »
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
The 11th plague of Egypt
|
 |
Reply #36 Posted on: March 14, 2010, 11:21:45 am |
|
|
 Joined: Dec 2009
Posts: 274
|
No, let's try to explain what a type is.
A type is the type of the variable you want to declare. This is how you use it in C++
char is the type used to declare a character variable char a = 'a';
int is the type used to declare an integer variable int a = 1;
double is the type used to declare a double precision floating point variable double a = 3,14;
var is an all comprehensive type: you can use it to declare any type of variable you want, it makes your life simpler, but it performs bad var a = 'a'; var b = 1; var c = 3,14;
In GM you can declare a variable without defining its type. b = 1; In C++, you NEED to declare the type, or it won't work. Of course Enigma will make it work anyway, but it will perform less faster.
In C++, and in any real coding language, when you declare a variable, that variable will only be usable inside the block of code you declare it in. So, in GML you can do this for ( i=0; i<10; i+=1) { a=i; } a=3;
In C++ the variable "a" will be deallocated after the last }, so if you wanted to use "a" outside the block, you have to declare it outside int a; for (int i=0; i<10; i++) { a=i; } a=3;
So, if you make any int variable work at an object level, instead of deallocating it, that will break an important C++ feature. Please people, vote for the first option, your GML programs will work anyway, but you won't break our C++ codes.
|
|
|
Logged
|
|
|
|
Josh @ Dreamland
|
 |
Reply #37 Posted on: March 14, 2010, 11:23:23 am |
|
|
Prince of all Goldfish
 Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
My thoughts ^
Breaks this v
if (true) { var a; a = 3.14; } show_message(string(a));
And by "breaks," I mean "fixes in a way that may piss off a very small percentage of GM users."
|
|
« Last Edit: March 14, 2010, 11:24:55 am by Josh @ Dreamland »
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
 |
Reply #39 Posted on: March 14, 2010, 12:44:11 pm |
|
|
Prince of all Goldfish
 Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Game_boy: Should make that a priority, actually.
All of those will. Even global var, which will be done like so: #define globalvar global var ...heh.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
polygone
|
 |
Reply #40 Posted on: March 14, 2010, 01:49:57 pm |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
My thoughts ^
Breaks this v
if (true) { var a; a = 3.14; } show_message(string(a));
And by "breaks," I mean "fixes in a way that may piss off a very small percentage of GM users."
Whoever uses that code in gml is retarded, who cares how gml handles it, it shouldn't be written.
|
|
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
Game_boy
|
 |
Reply #41 Posted on: March 15, 2010, 12:33:13 pm |
|
|
 Joined: Apr 2008
Posts: 228
|
Whoever uses that code in gml is retarded, who cares how gml handles it, it shouldn't be written.
Slippery slope to all GM code being retarded, C++ is much better. Which may be true, but that's not the point. Everything GM does but Enigma doesn't will make a the number of people who switch smaller. No matter how justified the reason for the incompatibility is.
|
|
|
Logged
|
|
|
|
polygone
|
 |
Reply #42 Posted on: March 15, 2010, 02:38:03 pm |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
I would be highly surprised if there is one single user using that code that will switch from GM to Enigma, it's irrelevant. The reasons for this: 1) Most users only declare var at the top of a script. 2) Most people with the knowledge to use var would not make such a mistake. 3) I would also expect an average GM user switching to Enigma to be more intelligent. Slippery slope to all GM code being retarded That above code is illogical it shouldn't even be used in GM, the same is not said for all gml.
|
|
« Last Edit: March 15, 2010, 02:41:44 pm by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
polygone
|
 |
Reply #44 Posted on: March 15, 2010, 06:51:37 pm |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
Yes but I bet noone in the history of moving from GM to Enigma will ever use code in that format for the reasons mentioned above. I may be wrong perhaps one person may at some point may use it but it's really not even worth considering for the off change of slightly annoying that one person.
|
|
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|