Poll
Question: How should an object-local and a script-local integer be defined?
local int, int - 12 (63.2%)
int, var int - 6 (31.6%)
localv int, int - 0 (0%)
Special Event - 1 (5.3%)
Total Members Voted: 19

Pages: « 1 2 3 4 5 »
  Print  
Author Topic: Another choice.  (Read 9960 times)
Offline (Unknown gender) The 11th plague of Egypt
Reply #30 Posted on: March 14, 2010, 06:23:26 AM
Member
Joined: Dec 2009
Posts: 276

View Profile
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
Offline (Unknown gender) score_under
Reply #31 Posted on: March 14, 2010, 07:02:31 AM

Member
Joined: Aug 2008
Posts: 308

View Profile
it's better not add it in a GM style.
Which, IIRC, is the use of some badly-made GEX, and the "feature" being added is usually a little get_string box which accepts a single password to set lives to 200 or something, and does a show_message on both correct and incorrect attempts. And then people post in the topic saying "Wow, this is amazing" and "How do I install GEX?".
Logged
Offline (Unknown gender) Game_boy
Reply #32 Posted on: March 14, 2010, 08:51:22 AM
Member
Joined: Apr 2008
Posts: 228

View Profile
"Game_boy: when you think about "var" as a class rather than simply a keyword, does it seem more logical? Or less?"

*head explodes*

So var and int are like GM objects now? Is that what you mean? And they can have their own variables?

If so, I can see why 'int, var int' makes no sense. But why do int and var being GM objects mean that their scope is in the script only?

I'm confused by the terminology here. I'm not really sure what you mean by 'class', 'keyword', 'type' or what 'local' would be (keyword? class?).

Logged
Offline (Male) Josh @ Dreamland
Reply #33 Posted on: March 14, 2010, 11:05:04 AM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
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:
Code: [Select]
struct vector
{
  double direction;
  double magnitude;
}

You could then declare and manipulate an array of them like this:
Code: [Select]
  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:

Code: [Select]
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):

Code: [Select]
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
Offline (Male) retep998
Reply #34 Posted on: March 14, 2010, 11:11:12 AM

Member
Location: Where else?
Joined: Jan 2010
Posts: 248
MSN Messenger - retep998@charter.net AOL Instant Messenger - retep998 Yahoo Instant Messenger - retep998
View Profile Email
This is the behavior of gm:

Quote
1) Tell Game Maker that this variable should be treated local to the script, as a keyword (Wow! that's what var does!)
2) Mark intended for "var" only to signify that the variable was local to the code.
2) Did he intend for the keyword to not be retroactive? That makes it behave more like a declaration than a keyword...
Logged
Offline (Male) Josh @ Dreamland
Reply #35 Posted on: March 14, 2010, 11:15:05 AM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
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,
Quote
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
Offline (Unknown gender) The 11th plague of Egypt
Reply #36 Posted on: March 14, 2010, 11:21:45 AM
Member
Joined: Dec 2009
Posts: 276

View Profile
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
Offline (Male) Josh @ Dreamland
Reply #37 Posted on: March 14, 2010, 11:23:23 AM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
My thoughts ^

Breaks this v
Code: [Select]
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
Offline (Unknown gender) Game_boy
Reply #38 Posted on: March 14, 2010, 12:19:31 PM
Member
Joined: Apr 2008
Posts: 228

View Profile
OK. I think I understand.

My main principle is that whatever Josh does shouldn't break a single line of GM, not even in odd cases no one uses. So:

"a" should work exactly like GM
"var a" should work exactly like GM
"globalvar a" should work exactly like GM
Everything else should work like "local int, int" because that's how C++ should work.

And the manual/website should go out of its way to point that out, with examples, because it'll be the first Enigma-specific feature a GM user adopts. Whereas the C++ users will get used more easily to the idea that GM is backwards with var.
« Last Edit: March 14, 2010, 12:21:26 PM by Game_boy » Logged
Offline (Male) Josh @ Dreamland
Reply #39 Posted on: March 14, 2010, 12:44:11 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
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
Offline (Male) polygone
Reply #40 Posted on: March 14, 2010, 01:49:57 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
My thoughts ^

Breaks this v
Code: [Select]
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.
Offline (Unknown gender) Game_boy
Reply #41 Posted on: March 15, 2010, 12:33:13 PM
Member
Joined: Apr 2008
Posts: 228

View Profile
Quote
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
Offline (Male) polygone
Reply #42 Posted on: March 15, 2010, 02:38:03 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
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.

Quote
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.
Offline (Female) IsmAvatar
Reply #43 Posted on: March 15, 2010, 06:00:44 PM

LateralGM Developer
LGM Developer
Location: Pennsylvania/USA
Joined: Apr 2008
Posts: 886

View Profile Email
Doesn't really matter if it should or shouldn't be used - someone uses it in some game, and they expect to convert said game directly to C++ with Enigma, which is a fairly reasonable expectation. Suppose the following:

Create event: i = 10 //maybe this represents lives
Some other event:
Code: [Select]
if (hits > 10) { //every 10 hits, they lose all their weapons
 var i;
 for (i = 0; i < 5; i += 1) { weapon[i] = 0; }
}
...
i -= 1; //we're reducing the number of lives this player has



Also, for amusement purposes, this is my 69th post...


« Last Edit: March 15, 2010, 06:04:38 PM by IsmAvatar » Logged
Offline (Male) polygone
Reply #44 Posted on: March 15, 2010, 06:51:37 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
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.
Pages: « 1 2 3 4 5 »
  Print