Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Please help me implement my expression, stupid mistake somewhere

  • Please help me implement my expression, stupid mistake somewhere

    Posted by Simon Ličman on January 31, 2021 at 8:50 am

    Hello, my expression is supposed to be placed at solid layer´ s opacity channel and solid has “advanced lightning” effect to it. Purpose of this expression is to procedurally turn opacity from 0 to 100 fast for random time interval (keep glowing) and after that turn fast to 0, wait random time with value 0, and then again raise up to 100 for few secs and then fade away again, so i have relatively realistic lightnings opacity, i dont care about anything else, i just couldnt use random twitching on this because lightning strikes need a small breaks in between to appear real. I am absolutely new to expressions and i teamed this up with senior java programmer, we both assumed at a time of writing that assigning global variable to a slider is as simple as “a=5; thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) = a;”, i dont know how to do any better. There are 3 variables that are meant to be global:

    nextStartTime = 0;
    curValue = 0;
    isGrow = 0;

    so they are assigned to a slider and referenced to an expression, meanwhile they are also rewritten by expression. My implementation of expression looks like this:

    stepFlash = 10; // Prirustek intezity blesku
    bleskCekaOdSec = 1;
    bleskCekaDoSec = 10;
    bezBleskuCekaOdSec = 5;
    bezBleskuCekaDoSec = 10;
    if (time > thisComp.layer(“Null1”).effect(“nextStartTime”)(“Slider”)) {
    if (thisComp.layer(“Null1”).effect(“isGrow”)(“Slider”) == 1) {
    // Roste
    if (thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) < 100) {
    // Zvedam hodnotu
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) += stepFlash;
    } else {
    // 100 nebo více
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) = 100; // Nastavim maximalni hodnotu
    // Interval pro delku cekani s rozsvicenym bleskem
    seedRandom(1, false);
    thisComp.layer(“Null1”).effect(“nextStartTime”)(“Slider”) += random(bleskCekaOdSec, bleskCekaDoSec);
    // Oznacim pro pokles hodnoty
    thisComp.layer(“Null1”).effect(“isGrow”)(“Slider”) = 0;
    }
    } else {
    // Klesa
    if (thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) > 0) {
    // Snizuji hodnotu
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) -= stepFlash;
    } else {
    // 0 nebo mene
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) = 0; // Nastavim minimalni hodnotu
    // Interval pro delku cekani bez blesku
    seedRandom(1, false);
    thisComp.layer(“Null1”).effect(“nextStartTime”)(“Slider”) += random(bezBleskuCekaOdSec, bezBleskuCekaDoSec);
    // Oznacim pro rust hodnoty
    thisComp.layer(“Null1”).effect(“isGrow”)(“Slider”) = 1;
    }
    }
    }
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”)

    ——

    But there is raw expression we wrote yesterday:

    // Global variables
    nextStartTime = 0;
    curValue = 0;
    isGrow = 0;

    stepFlash = 10; // Prirustek intezity blesku
    bleskCekaOdSec = 1;
    bleskCekaDoSec = 10;
    bezBleskuCekaOdSec = 5;
    bezBleskuCekaDoSec = 10;

    if (time > thisComp.layer(“Null1”).effect(“nextStartTime”)(“Slider”)) {
    if (thisComp.layer(“Null1”).effect(“isGrow”)(“Slider”) == 1) {
    // Roste
    if (thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) < 100) {
    // Zvedam hodnotu
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) += stepFlash;
    } else {
    // 100 nebo více
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) = 100; // Nastavim maximalni hodnotu
    // Interval pro delku cekani s rozsvicenym bleskem
    seedRandom(1, false);
    thisComp.layer(“Null1”).effect(“nextStartTime”)(“Slider”) += random(bleskCekaOdSec, bleskCekaDoSec);
    // Oznacim pro pokles hodnoty
    thisComp.layer(“Null1”).effect(“isGrow”)(“Slider”) = 0;
    }
    } else {
    // Klesa
    if (thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) > 0) {
    // Snizuji hodnotu
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) -= stepFlash;
    } else {
    // 0 nebo mene
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”) = 0; // Nastavim minimalni hodnotu
    // Interval pro delku cekani bez blesku
    seedRandom(1, false);
    thisComp.layer(“Null1”).effect(“nextStartTime”)(“Slider”) += random(bezBleskuCekaOdSec, bezBleskuCekaDoSec);
    // Oznacim pro rust hodnoty
    thisComp.layer(“Null1”).effect(“isGrow”)(“Slider”) = 1;
    }
    }
    }
    thisComp.layer(“Null1”).effect(“curValue”)(“Slider”);

    —–

    Any help is going to be very much appreciated, thank you!

    Simon Ličman replied 5 years, 7 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy