Page 1 of 1

reference the parent object in a globally defined funtion

Posted: 04 Dec 2012 09:48
by bananas
Hard to explain this without the patch, so i have attached it here.


in 'global_function()' , I have this line:

Monitor.monitor_value = getexpression(Fader_1,'x') + 1;


but i don't want "Fader_1" in there, i want something like getobjectparent()... so that my global function can be called by any Faders, not just Fader_1.

so i tried getobjectparent(), and i tried getobject(), but neither of them were doing what i wanted. Is there some trick i'm missing?

Re: reference the parent object in a globally defined funtio

Posted: 04 Dec 2012 11:10
by Macciza
Hi

Maybe come at it slightly differently - just get the Fader to send the value to the function . . .

global_function(x) -(you pass a value along as x)
Monitor.value = x + 1; // don't need to recast as monitor_value and then to value just use Monitor.value - samething

Fader_script becomes Execute on Expression 'x'
global_function(x); // this sends the local x value to the function which adds 1 and puts it to the monitor value

You can duplicate the Fader multiple times and they will all post to the same Monitor object
Is that what you wanted??

MM

Re: reference the parent object in a globally defined funtio

Posted: 04 Dec 2012 12:46
by bananas
Macciza wrote:Hi


global_function(x) -(you pass a value along as x)
but...i thought functions didn't take arguments?

can you have a look at my patch and modify it so it does that???

Re: reference the parent object in a globally defined funtio

Posted: 04 Dec 2012 12:52
by bananas
by the way, i know in this case it would be much easier just to send the Fader_1.x value directly to the monitor... but this is just an example patch, which demonstrates what i wish to achieve.

I need to learn this process: ie, how to declare global functions and then use them inside my faders, switches, etc

Re: reference the parent object in a globally defined funtio

Posted: 04 Dec 2012 12:56
by bananas
oh....!

just made a global function by typing 'global_function(x)' and that worked :D

please ignore my stupidity :D

i'm learning lemur and script coding both at the same time.

Re: reference the parent object in a globally defined funtio

Posted: 04 Dec 2012 13:08
by bananas
woo!

i got it!

sorry about the noise and silly comments....Macciza, your method is exactly what i needed

Re: reference the parent object in a globally defined funtio

Posted: 04 Dec 2012 14:43
by Macciza
Hi
Basically functions can be defined to either take arguments or not as needed by naming them appropriately

global_function(x) means it takes one arg that is accessed in the script as 'x'
Additional args need additional vars ie global_function(x,offset) and use Monitor.value=x+offset and send global_function(x,2) from the Fader script

Hope that makes sense
MM

Re: reference the parent object in a globally defined funtio

Posted: 04 Dec 2012 15:43
by bananas
awesome. yeah....i understand ( i hope)