Pages: [1] 2
  Print  
Author Topic: Object member functons  (Read 2960 times)
Offline (Male) RetroX
Posted on: January 06, 2011, 07:50:50 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
It would be really cool if, somehow, ENIGMA would be able to do something like:
Code: [Select]
obj.instance_destroy();instead of:
Code: [Select]
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:
Code: [Select]
obj.f1();
obj.f2();
would be parsed to:
Code: [Select]
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)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Unknown gender) freezway
Reply #1 Posted on: January 06, 2011, 08:07:31 PM

Member
Joined: Dec 2009
Posts: 220

View Profile
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
Offline (Female) IsmAvatar
Reply #2 Posted on: January 06, 2011, 09:53:06 PM

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

View Profile Email
I'm with you.
Logged
Post made January 07, 2011, 02:52:03 AM was deleted at the author's request.
Offline (Male) polygone
Reply #4 Posted on: January 07, 2011, 07:44:26 AM

Contributor
Location: England
Joined: Mar 2009
Posts: 810

View Profile
Given this suggestion, how would this be interpreted?

Code: (EDL) [Select]
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.
Offline (Unknown gender) luiscubal
Reply #5 Posted on: January 07, 2011, 12:04:39 PM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
@polygone

Code: (EDL) [Select]
//a declared outside the with
with (obj)
   a = obj.f1();
Logged
Offline (Male) polygone
Reply #6 Posted on: January 07, 2011, 12:33:57 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 810

View Profile
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.
Offline (Male) RetroX
Reply #7 Posted on: January 07, 2011, 04:05:33 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Given this suggestion, how would this be interpreted?

Code: (EDL) [Select]
a = obj.f1();
Code: [Select]
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)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Male) polygone
Reply #8 Posted on: January 07, 2011, 04:45:39 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 810

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

Code: [Select]
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.
Offline (Male) RetroX
Reply #9 Posted on: January 07, 2011, 05:03:13 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Yeah, that would make sense.  Still think that it would be a good idea to have an option for all objects, though.
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)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Male) polygone
Reply #10 Posted on: January 07, 2011, 05:08:36 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 810

View Profile
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.
« 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.
Offline (Male) RetroX
Reply #11 Posted on: January 07, 2011, 05:21:05 PM

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
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.
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)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Offline (Male) polygone
Reply #12 Posted on: January 07, 2011, 05:44:56 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 810

View Profile
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()];
« 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.
Offline (Female) IsmAvatar
Reply #13 Posted on: January 07, 2011, 06:04:27 PM

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

View Profile Email
You're going to have to explain that one to me... because I don't see what's wrong with it.
Logged
Offline (Male) polygone
Reply #14 Posted on: January 07, 2011, 06:12:54 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 810

View Profile
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.
Pages: [1] 2
  Print