Page 1 of 1

Dot notation for object attributes

Posted: 15 Jan 2013 03:52
by dBlicious
Got my Lemur app about a week ago and am diving headfirst into scripting. Most of my programming experience is with javascript, so I want to make my scripting more object oriented. One of the first things I noticed is the cumbersome way to get and set object attributes. Fortunately it wasn't too difficult to fix this. With a little scripting I can do this:

Code: Select all

MultiSlider.nbr = 16;
x = MultiSlider.nbr;
instead of this:

Code: Select all

setattribute(MultiSlider, 'nbr', 16);
x = getattribute(Multislider, 'nbr');
I was thinking of making custom modules for all the objects and their attributes. Before I start, has anyone already done this and wouldn't mind sharing their work? If not, would anyone else find it useful?

-A

Re: Dot notation for object attributes

Posted: 15 Jan 2013 05:04
by Phil999
I think you found a good method. I am using both, but still not sure when to use which. Sometimes you can use the '=', sometimes you have to use the set/getattribute().

One year of experience (me), and still unsure about fundamental things. :)

Re: Dot notation for object attributes

Posted: 16 Jan 2013 02:10
by Macciza
Hi

Yes you can make attibutes act like variables - I do similar stuff sometimes with modules to expose vars at a higher level . . .

Though, I would suggest learning a bit more about Lemur scripting before over-riding basic syntax - you may find issues with your approach later on. . .

Dot.notation applies to variables - get/setattribute applies to attributes . . .

MM

Re: Dot notation for object attributes

Posted: 16 Jan 2013 13:15
by Phil999
thanks for clarifying.

But a dot.notation is the same as an object expression? Not quite, isn't it? It's not on the same 'level'?

Re: Dot notation for object attributes

Posted: 16 Jan 2013 15:06
by dBlicious
Macciza wrote: Though, I would suggest learning a bit more about Lemur scripting before over-riding basic syntax - you may find issues with your approach later on. . .
MM
MM, can you think of any possible issues to be aware of? Aside from the tedium of implementing it? :D The big problem I see is changing an attribute directly after the referencing expression is initialized. I think that should easily be avoided if I'm not careless, but I might be overlooking something due to my lack of experience. I can see the possibility of painting myself into a corner. I guess it's safest to start off small and see how that goes.

Re: Dot notation for object attributes

Posted: 17 Jan 2013 10:52
by Macciza
Hi
Hard to say without seeing what you're doing . ..
But there will be bloat if you add it to everything and use a lot of objects etc
It may may it difficult to understand standard Lemur programming as you wont have learnt it . .
Others may find your Projects difficult to understand or use bits of due to your over-riding . . .
Somethings that are standard practice may give unexpected results

Send in an example of how you might approach it
And run comprehensive tests to evaluate that things do work . . .

Usually attributes are not used as much or in the same way as object variables so it is hard to say how much actual advantage you may gain
I can see that it nmay be handy in certain instances but feel it is probably best on a per case basis for certain attributes of certain objects rather than open slather . . .

Cheers
MM