RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Posted on: January 07, 2011, 12:50:50 AM |
|
|
|
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.
|
|
|
freezway
 Joined: Jan 2010
Posts: 220
|
 |
Reply #1 Posted on: January 07, 2011, 01:07:31 AM |
|
|
|
AGREED!
|
|
|
IsmAvatar
LateralGM Developer
 Joined: Apr 2008
Posts: 877
|
 |
Reply #2 Posted on: January 07, 2011, 02:53:06 AM |
|
|
|
I'm with you.
|
|
|
|
Post made January 07, 2011, 07:52:03 AM was deleted at the author's request.
|
polygone
 Joined: Mar 2009
Posts: 794
|
 |
Reply #4 Posted on: January 07, 2011, 12:44:26 PM |
|
|
|
Given this suggestion, how would this be interpreted?
a = obj.f1();
|
|
|
luiscubal
 Joined: Jun 2009
Posts: 452
|
 |
Reply #5 Posted on: January 07, 2011, 05:04:39 PM |
|
|
|
@polygone
//a declared outside the with with (obj) a = obj.f1();
|
|
|
polygone
 Joined: Mar 2009
Posts: 794
|
 |
Reply #6 Posted on: January 07, 2011, 05:33:57 PM |
|
|
|
What?
Anyway never-mind it would clearly have to syntax error. This couldn't be used for anything other than straight executing functions.
|
|
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #7 Posted on: January 07, 2011, 09:05:33 PM |
|
|
Quote from: polygone on January 07, 2011, 12:44:26 PM 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.
|
|
|
polygone
 Joined: Mar 2009
Posts: 794
|
 |
Reply #8 Posted on: January 07, 2011, 09:45:39 PM |
|
|
|
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.
|
|
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #9 Posted on: January 07, 2011, 10:03:13 PM |
|
|
|
Yeah, that would make sense. Still think that it would be a good idea to have an option for all objects, though.
|
|
|
polygone
 Joined: Mar 2009
Posts: 794
|
 |
Reply #10 Posted on: January 07, 2011, 10:08:36 PM |
|
|
Quote from: RetroX on January 07, 2011, 10:03:13 PM 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.
|
|
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #11 Posted on: January 07, 2011, 10:21:05 PM |
|
|
|
That's why I'm saying that it should be made as an option. :V
Use member functions like regular variables. Then, add a configuration option to make both variables and functions operate on all objects.
|
|
|
polygone
 Joined: Mar 2009
Posts: 794
|
 |
Reply #12 Posted on: January 07, 2011, 10:44:56 PM |
|
|
Quote from: RetroX on January 07, 2011, 10:21:05 PM 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()];
|
|
|
IsmAvatar
LateralGM Developer
 Joined: Apr 2008
Posts: 877
|
 |
Reply #13 Posted on: January 07, 2011, 11:04:27 PM |
|
|
|
You're going to have to explain that one to me... because I don't see what's wrong with it.
|
|
|
polygone
 Joined: Mar 2009
Posts: 794
|
 |
Reply #14 Posted on: January 07, 2011, 11:12:54 PM |
|
|
|
How would that be interpreted?
|
|
|
|