RetroX
|
 |
Posted on: January 06, 2011, 07:50:50 pm |
|
|
Master of all things Linux
 Location: US Joined: Apr 2008
Posts: 1055
|
It would be really cool if, somehow, ENIGMA would be able to do something like:
obj.instance_destroy(); instead of:
with(obj) { instance_destroy(); } Basically, calling a function as a member function would merely mean applying it as a with() statement with only one line. And there might be optimisations for it, too, for example:
obj.f1(); obj.f2(); would be parsed to:
with (obj) { f1(); f2(); } Granted, you could abuse this and do things like obj.draw_set_color(), but it's still a nicer syntax (and you can do that in with(), too). Obviously, with() would have to be used for ifs and loops, but for simple functions, writing it out this way just looks nicer.
I dunno how doable that this would be, but I think that it would be a really nice thing to have.
|
|
|
Logged
|
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)Why do all the pro-Microsoft people have troll avatars? 
|
|
|
freezway
|
 |
Reply #1 Posted on: January 06, 2011, 08:07:31 pm |
|
|
 Joined: Dec 2009
Posts: 220
|
AGREED!
|
|
|
Logged
|
if you drop a cat with buttered toast strapped to its back, which side lands down? joshdreamland: our languages are based on the idea that it's going to end up FUBAR /kick retep998
|
|
|
|
Post made January 07, 2011, 02:52:03 am was deleted at the author's request.
|
polygone
|
 |
Reply #4 Posted on: January 07, 2011, 07:44:26 am |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
Given this suggestion, how would this be interpreted?
a = obj.f1();
|
|
« Last Edit: January 07, 2011, 11:48:09 am by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
polygone
|
 |
Reply #6 Posted on: January 07, 2011, 12:33:57 pm |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
What?
Anyway never-mind it would clearly have to syntax error. This couldn't be used for anything other than straight executing functions.
|
|
« Last Edit: January 07, 2011, 12:44:51 pm by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
RetroX
|
 |
Reply #7 Posted on: January 07, 2011, 04:05:33 pm |
|
|
Master of all things Linux
 Location: US Joined: Apr 2008
Posts: 1055
|
Given this suggestion, how would this be interpreted?
a = obj.f1(); global var ______ENIGMATEMP; with (obj) { ______ENIGMATEMP = f1(); } a = ______ENIGMATEMP; By "parse," I didn't mean textually. I meant to replicate its usage. All that with() does is change enigma::instance_event_iter to the current object. a = obj.f1() simply would mean change the event iter, however, operate on a local variable.
|
|
« Last Edit: January 07, 2011, 04:19:58 pm by RetroX »
|
Logged
|
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)Why do all the pro-Microsoft people have troll avatars? 
|
|
|
polygone
|
 |
Reply #8 Posted on: January 07, 2011, 04:45:39 pm |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
Using with seems counter-intuitive to me given how gml works. Because when an object_index is given in gml in variable assignment it only assigns to the first instance of the object, unlike with which assigns to all the instances.
obj.a = value; //assigns to just the first instance of obj
with (obj) { a = value; //assign to all instances of obj } Thus if the dot syntax was used for executing functions it seems better to me if it does not use with, but rather only executes to the first instance of obj in order to keep the notation consistent.
|
|
« Last Edit: January 07, 2011, 05:06:21 pm by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
polygone
|
 |
Reply #10 Posted on: January 07, 2011, 05:08:36 pm |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
Yeah, that would make sense. Still think that it would be a good idea to have an option for all objects, though.
Given that you would want to change the object_index.variable = value interpretation to every instance at the same time. Otherwise this code would be counter-intuitive: obj.a = obj.f1(); As it would only assign a to the first instance of obj whereas it would loop f1() with all instances of obj. It is not possible though to change them to loop through all instances of objects because it will be too much work for the interpreter to do. Which is why I originally suggested it should just syntax error, but given that only the first instance of obj is used than I believe it is doable, it would just be like replacing obj.f1() to the return value of f1() executed in the scope of the first instance of obj.
|
|
« Last Edit: January 07, 2011, 05:52:46 pm by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
polygone
|
 |
Reply #12 Posted on: January 07, 2011, 05:44:56 pm |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
Then, add a configuration option to make both variables and functions operate on all objects.
It's not reasonable to let them to be changed to loop through all instances otherwise you can start doing all sorts of crazy shit. Like this: obj1.a = obj2.array[obj1.f1(), obj2.f2()];
|
|
« Last Edit: January 07, 2011, 05:54:00 pm by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
polygone
|
 |
Reply #14 Posted on: January 07, 2011, 06:12:54 pm |
|
|
 Location: England Joined: Mar 2009
Posts: 794
|
How would that be interpreted?
|
|
« Last Edit: January 07, 2011, 06:19:21 pm by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|