Jump to content

tiscavalcanti

Members
  • Posts

    46
  • Joined

  • Last visited

Posts posted by tiscavalcanti

  1. Hello, I'm needing to write code that do the following.
    Take two values: [x, y];
    And using conditions change within functions.
    The following is:
    var x = 0;var y = 0;var b = 2;var c = 3;So;first function of x = valueXOffset (xFunctionFirst) // OffsetIf b = 1return{96 // 5% of 1920}y = 54 // 5% of 1080Else if b = 2return{192 // 10% of 1920}y = 108 // 10% of 1080Else if b = 3return{288 // 15% of 1920}y = 162 // 15% of 1080Else b = (any value)return{0}y = 0second function of x = valueXFinal (xFunctionSecond)If c = 1return{xFunctionFirst}Else If c = 2return{1920/2}Else If c = 3return{1920 - xFunctionFirst}Else c = (any value)0call function here, to get x value and y too.[x, y];
    By "y" get stuck within a function, have to follow the conditions, it must be called in the last function.
    I think you need to use two functions, something like this example:
    the function (x) {// <- function
    function b (y) {// <- inner function
    return x + y; // <- Use variables from outer scope
    }
    return b; // <- You can even return to function.
    }
    to (3) (4);
    And each function use two parameters to represent x and y.
    As a way to array.
    In the function of "x", if you need to call a value, which is 1920.
    And in function of "y" 1080.
    What this code does is every time I increase 1-3, b, x rise or fall by 5%, and y will increase by 5% from 1 to 1.
    And 1 to 3 passes c 0 + offset, 960 = half, and then in 1920, the total - offset.

    The restrictions I have, it is to be done with functions, please.

  2.  

    You can have your function return an array, but unless you're operating a and z together in two different ways, I don't see a reason to do it.

     

    Returning both values with an array:

    function val(a, z) {  return [ a/2, z+8 ];}

    A better approach:

    function half(x) {  return x/2;}function plus8(x) {  return x + 8;}

    Thank you!

  3. w = thisComp.width;h = thisComp.height;s = 0;p = [.95, .90, .85, .15, .10, .05];x = value[0];y = value[1];function getLayerName(theLayer,theName,theParm){  try{    return theLayer.effect(theName)(theParm).name;  }catch(err){    return "None";  }}L = thisComp.layer("Less");a = getLayerName(L,"Scale","Layer");b = getLayerName(L,"Position","Layer");c = getLayerName(L,"Side","Layer");

    This is it.

  4. You can set up an object like this and then use it to populate the variables with the values:

    var obj = {  a: 'Scale',  b: 'Position',  c: 'Side'};
    You could loop through the properties of that object and use them to set the variables with their corresponding values, but doing that is not going to improve efficiency. It might make the code shorter, but it's more efficient to just execute each statement individually rather than looping.

     

    Thank you! I understand.

  5. It still isn't clear to me what code you are replacing with this loop.

     

    You say...

     

     

    ...so show us a dozen lines of code.

    After I managed to go ahead on the understanding of "for" loops and functions, I realized that there really is not a way to make a loop or function, use the instruction always use the same base code: (thisComp.effect ("")("Layer") name;), adding effect name (Scale, Position, Side) in half and then, generating variables (a, b, c), each getting one line of code ready. (as a factory cakes, which uses always the same base recipe, and only adds a special ingredient for each cake, making cakes with different flavors, for example). But if there is a another way to do this, let me know please.
    Actually, I just wanted a way to simplify my code, but I realized that is not feasible.
    Because just getting more complicated, what was simpler. Sorry to ask a question without much foundation.
  6. Oh, yeah!

    I want to optimize this expression.

    
    
    
    
    // Position    // Variables:  var w=1920;     // Comp Width  var h=1080;     // Comp Height  var p1=.95;     // variable to multiply by 95%  var p2=.90;     // variable to multiply by 90%  var p3=.85;     // variable to multiply by 85%  var p4=.15;     // variable to multiply by 15%  var p5=.10;     // variable to multiply by 10%  var p6=.05;     // variable to multiply by 5%  var s;          // variable to be modified  var x;          // variable to represent Width Property value  var y;          // variable to represent Height Property value    // Variables with Try/Catch Block to Prevent errors:    // (I wanted to simplify the part below, making it more optimized.)    try{  a=thisComp.layer("Less").effect("Scale")("Layer").name;     // Variable = "Scale" - Layer Control Effect  }catch(err){  a=0;        // Prevention for when the effect is selected "None".  };  try{  b=thisComp.layer("Less").effect("Position")("Layer").name;      // Variable = "Position" - Layer Control Effect  }catch(err){  b=0;        // Prevention for when the effect is selected "None".  };  try{  c=thisComp.layer("Less").effect("Side")("Layer").name;      // Variable = "Side" - Layer Control Effect  }catch(err){  c=0;        // Prevention for when the effect is selected "None".  };    // Conditions:    // (I wanted to simplify these conditions with functions or loops, for example.)    if(thisComp.layer("Less").effect("Master Control")("Checkbox")==0){     // Condition to when Checkbox is disabled, the property back to original value  value;  }else{      // And otherwise  if(b=="Less"){      // If "Position" - Layer Control Effect = Layer "Less"  y=h*p1;     // Height value = Comp height * 95% | Result = 1026  s=w*p6;     // variable s = Comp width * 5% | Result = 96  }else if((b=="Half") || (b=="Default")){        // Otherwise, If "Position" - Layer Control Effect = Layer "Half" or "Default"  y=h*p2;     // Height value = Comp height * 90% | Result = 972  s=w*p5;     // variable s = Comp width * 10% | Result = 192  }else if(b=="More"){        // Otherwise, If "Position" - Layer Control Effect = Layer "More"  y=h*p3;     // Height value  = Comp height * 85% | Result = 918  s=w*p4;     // variable s = Comp width * 15% | Result = 288  }else{      // And otherwise  y=value[1];     // Height value = Original value  };  if(a==0){       //  If "Scale" - Layer Control Effect = None  x=w/2;      // width value = Comp Width / 2 | Result = 960  }else{      // And otherwise  if((c=="Less") || (c=="Default")){      // If "Side" - Layer Control Effect = Layer "Less" or "Default"  x=s;        // Width value = variable s  }else if(c=="Half"){          // Otherwise, If "Side" - Layer Control Effect = Layer "Half"  x=w/2;      // Width value = Comp width / 2 | Result = 960  }else if(c=="More"){          // Otherwise, If "Side" - Layer Control Effect = Layer "More"  x=w-s;      // Width value = Comp width - variable s  }else{      // And otherwise  x=value[0];     // Width value = Original value  };  };  [x,y]       // Property | Array = Final Value of Width and Height  };  
  7. That looks like code from some sort of animation framework. What exactly is it? Adobe After Effects?

    What I want is to actually simplify the code, to avoid repetition.

     

    I want to avoid of writing dozens of times, the same base of effect code to save rewrite that part:
    thisComp.effect("")("Layer").name;
    Because the expression in general, becomes very extensive and more difficult to edit with lot of effects.
    So I want a way to use a loop that collects all the names of the effects, and use the base of effect code above which is repeated, to receive these names: "Scale", "Position" & "Side", and generate 3 full effects separately, with this output:
    thisComp.effect("Scale")("Layer").name;
    thisComp.effect("Position")("Layer").name;
    thisComp.effect("Side")("Layer").name;
    And finally, take these three generated effects, and connect them to 3 variables... a, b and c.
    It is possible?
    I'm beginner with functions and loops.
  8. That looks like code from some sort of animation framework. What exactly is it? Adobe After Effects?

    var names=["Scale", "Position", "Side"];
    for (var i = 0; i < names.length; i++) {
    var val="thisComp.effect(" +names +")('Layer').name";
    }
    the result of "var val" is this:
    thisComp.effect(Scale)('Layer').namethisComp.effect(Position)('Layer').namethisComp.effect(Side)('Layer').name
    I can arrive until here.
    But it's all together. I wanted to separate each line, now for each variable. A, B and C.
    Lack take each line of output to a variable.
  9. I need to create a code that take the following strings:
    "Scale"
    "Position"
    "Side"
    And put each one, within of a copy of this code:
    thisComp.effect(!!!STRING HERE!!!)("Layer").name;
    And after that, three variables, each one, receive a complete code.
    var a;
    var b;
    var c;
    The result would be this:
    var a = thisComp.effect("Scale")("Layer").name;  var b = thisComp.effect("Position")("Layer").name;  var c = thisComp.effect("Side")("Layer").name;  
    I try made like this:
    var strings = ["Scale", "Position", "Side"];
    var val = function (a, b, c){
    for (var i=0; i<strings.length; i++){
    var effect=thisComp.effect(strings)("Layer").name;
    val(effect);
    }
    }
    But no have experience with functions and For Loops.
    And no know if this is the correct way of do it.
    I need to do this because my code is becoming too long for many repetitions.
    I think for that, will need to use for loop, and function.
    Thanks.
  10. That MDN site has examples for all of the methods in the Math object. The other one is just some subtraction and division. Get started and ask questions if you get stuck.

    I got. Examples:

     

    .20*76 | 20% of 76 = 15.2

    1.20*76 | 76 + 20% = 91.2

    (1-.20)*76 | 76 - 20% = 60.8

     

    Calculate numerical difference between two values:

     

    (-8)+(3) = - 5 | balance value.

    (-8)-(3) = 11 | difference value.
    This is it. Thanks. :)
  11. I need make a calculation which allow know difference between two numbers. I can subtract the smallest of the larger, but this calculation is very limited, implies if a number is negative and the other positive.

     

    I want to know another way to do this.

    • It is possible to do this calculation in JavaScript through the:

    1. modulo;
    2. function;
    3. (Others);

    Mainly:

    Another important thing which I want, is to calculate percentage difference through two differents numbers. To know the value resultant.

     

    • I want to know all the possible ways to do this. Because I came across in an embarrassing situation in a video Software that uses expressions based on the JavaScript language.

     

    Thanks! :)

×
×
  • Create New...