Script for blinking lights

linoge8888linoge8888 Posts: 87

I want a script that automatically sets the intensity of a light source randomly between 20 and 200 every 3 frames within an animation. The script doesn't trigger any error but the intensity isn't modified at all. What's wrong ?

 

Post edited by linoge8888 on

Comments

  • barbultbarbult Posts: 24,836
    Maybe you should be changing luminosity value instead of intensity.
  • I tried but impossible to find the exact name of the parameter. I'm a beginniner, by the way.

  • CES3DCES3D Posts: 134
    edited February 9

    You need to make two corrections.

    The "Intensity" is displayed as a percentage, but the actual value you set is a real value where 100% equals 1.
    If you want to set the "Intensity" to a value between 20% and 200%, the argument you give to setValue should be a real number between 0.2 and 2.
    Therefore, getRandomIntensity() can be rewritten as follows, for example.

        // Generate a random number    function getRandomIntensity() {        var precision = 100;        return ( Math.floor( Math.random() * ( ( 200 - 20 ) * precision + 1 ) ) + 20 * precision ) / 100 / precision;    }


    DzTime is defined in ticks.
    There are 4800 ticks per second. In the case of 30 FPS, there are 160 ticks (4800 / 30) per frame.
    Therefore, the part where you calculate the time should be rewritten as follows

    var time = new DzTime( i * 4800 / 30 ); // 30 FPS

     

    With the two corrections above, your code should be working correctly.

    Screenshot 2025-02-09 201709.png
    2560 x 1400 - 360K
    Post edited by CES3D on
  • Thank you very much!

  • Richard HaseltineRichard Haseltine Posts: 102,701

    Note that there is no beenfit, and potential confusion, from declaring the variables inside the loop - they don't get created and destroyed on each iteration, they last (and are accessible) as long as the function is runing.

    You can get the actual start from frame directly, so if that is what you want it may be more flexible to use http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/animating/scene_time/start . Of course if this is a frame during the playrange then setting the value directly may well make more sense.

Sign In or Register to comment.