reference the parent object in a globally defined funtion

Discuss problems and solutions.
Post Reply
bananas
Newbie
Posts:33
Joined:29 Nov 2012 13:50
reference the parent object in a globally defined funtion

Post by bananas » 04 Dec 2012 09:48

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?
Attachments
global_func.jzml
(3.46KiB)Downloaded 100 times

Macciza
Regular
Posts:1325
Joined:07 Dec 2011 04:57
Location:Sydney, Australia.

Re: reference the parent object in a globally defined funtio

Post by Macciza » 04 Dec 2012 11:10

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
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]

bananas
Newbie
Posts:33
Joined:29 Nov 2012 13:50

Re: reference the parent object in a globally defined funtio

Post by bananas » 04 Dec 2012 12:46

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???

bananas
Newbie
Posts:33
Joined:29 Nov 2012 13:50

Re: reference the parent object in a globally defined funtio

Post by bananas » 04 Dec 2012 12:52

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

bananas
Newbie
Posts:33
Joined:29 Nov 2012 13:50

Re: reference the parent object in a globally defined funtio

Post by bananas » 04 Dec 2012 12:56

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.

bananas
Newbie
Posts:33
Joined:29 Nov 2012 13:50

Re: reference the parent object in a globally defined funtio

Post by bananas » 04 Dec 2012 13:08

woo!

i got it!

sorry about the noise and silly comments....Macciza, your method is exactly what i needed
Attachments
global_func2.jzml
(3.41KiB)Downloaded 102 times

Macciza
Regular
Posts:1325
Joined:07 Dec 2011 04:57
Location:Sydney, Australia.

Re: reference the parent object in a globally defined funtio

Post by Macciza » 04 Dec 2012 14:43

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
Attachments
global_func3.jzml
(23.1KiB)Downloaded 109 times
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]

bananas
Newbie
Posts:33
Joined:29 Nov 2012 13:50

Re: reference the parent object in a globally defined funtio

Post by bananas » 04 Dec 2012 15:43

awesome. yeah....i understand ( i hope)

Post Reply