again, an undefined error...

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

hey guys,

i'm using a function to create a comp, but i can't seem to reference this comp after the function creates it, despite telling the function to return my variable.


function shaderComp(shadingType) //Highlight or Shadow
{
//this function creates shading comps, HL or SHD, with appropriate solids and effects.

var shadingType = subFolder.items.addComp(layerName + " :: " + shadingType, layerWidth, layerHeight, layerPixelAspect, layerDuration, layerFrameRate);
return shadingType;
//the rest of my code has been commented out for debugging purposes
}

// call function
shaderComp("HL");

//add the HL comp to shadedComp,
//given that shadedComp is another previously created comp

var addFoo = shadedComp.layers.add(HL);

if i instead say var addFoo = shadedComp.layers.add(layerComp);
it works (layerComp being a previously created comp.

but i can't seem to do anything with my HL comp, which was created by the function.
var addFoo = shadedComp.layers.add(shadingType); doesn't work.

is there a step i'm missing? if i execute the commands normally (not as a function) it works. but as a function, it seems to go wrong somewhere.
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

quote:
var addFoo = shadedComp.layers.add(shadingType); doesn't work.

my bad, it does work. :)

but if i run the function multiple times, which comp will shadingType refer to? the most recently created one.

if, in a function, i use an argument as the name of the variable and then tell it to return this value, shouldn't it return it with the name of the argument, not the name of the argument-as-variable?

obviously it's returning shadingType from var shadingType, not shaderComp(shadingType).
they should be one and the same??????
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

i hope this isn't annoying anyone, the posting of problems and then my solutions about an hour later. :)

i figured out that i have to call the function like this:
hlComp = shaderComp("HL");

rather than just saying:
shaderComp("HL")

then i can say
var addFoo = shadedComp.layers.add(hlComp);

you learn something every day.
davestewart
Posts: 114
Joined: March 10th, 2005, 5:50 am
Location: London, UK
Contact:

On a good day, it's possible to learn LOTS of things! ;)
davestewart
Posts: 114
Joined: March 10th, 2005, 5:50 am
Location: London, UK
Contact:

Or should that be "On a bad day..." ?
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

well, hopefully these useless posts of mine will at least help someone else in the future!
:)
Post Reply