Pages: 1 2
Author Topic: Object member functons  (101,344 Views)
Offline (Unknown gender) RetroX

Master of all things Linux
Contributor
Joined: Apr 2008
Posts: 1,055
View profile
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.
Offline (Unknown gender) freezway

Member
Joined: Jan 2010
Posts: 220
View profile
Reply #1 Posted on: January 07, 2011, 01:07:31 AM
AGREED!
Offline (Unknown gender) IsmAvatar

LateralGM Developer
LGM Developer
Joined: Apr 2008
Posts: 877
View profile
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.
Offline (Unknown gender) polygone

Contributor
Joined: Mar 2009
Posts: 794
View profile
Reply #4 Posted on: January 07, 2011, 12:44:26 PM
Given this suggestion, how would this be interpreted?

Code (EDL) Select
a = obj.f1();
Offline (Unknown gender) luiscubal

Member
Joined: Jun 2009
Posts: 452
View profile
Reply #5 Posted on: January 07, 2011, 05:04:39 PM
@polygone

Code (EDL) Select

//a declared outside the with
with (obj)
   a = obj.f1();

Offline (Unknown gender) polygone

Contributor
Joined: Mar 2009
Posts: 794
View profile
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.
Offline (Unknown gender) RetroX

Master of all things Linux
Contributor
Joined: Apr 2008
Posts: 1,055
View profile
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?

Code (EDL) Select
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.
Offline (Unknown gender) polygone

Contributor
Joined: Mar 2009
Posts: 794
View profile
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.
Offline (Unknown gender) RetroX

Master of all things Linux
Contributor
Joined: Apr 2008
Posts: 1,055
View profile
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.
Offline (Unknown gender) polygone

Contributor
Joined: Mar 2009
Posts: 794
View profile
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:

Code (EDL) Select
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.
Offline (Unknown gender) RetroX

Master of all things Linux
Contributor
Joined: Apr 2008
Posts: 1,055
View profile
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.
Offline (Unknown gender) polygone

Contributor
Joined: Mar 2009
Posts: 794
View profile
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:

Code (EDL) Select
obj1.a = obj2.array[obj1.f1(), obj2.f2()];
Offline (Unknown gender) IsmAvatar

LateralGM Developer
LGM Developer
Joined: Apr 2008
Posts: 877
View profile
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.
Offline (Unknown gender) polygone

Contributor
Joined: Mar 2009
Posts: 794
View profile
Reply #14 Posted on: January 07, 2011, 11:12:54 PM
How would that be interpreted?
Pages: 1 2