• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Issue when using using logic in expressions

Community Beginner ,
Dec 04, 2022 Dec 04, 2022

Copy link to clipboard

Copied

I'm currently working on a project whereby at every frame an image has a 5% chance to flash on the screen for a duration of 2 frames. Otherwise the image is not visible.

After the image has flashed for 2 frames the image remains invisible for the rest of the timeline.

 

I have achieved this using 4 checkbox control's and a simple opacity script, 

 

  1.  The 1st checkbox (named 'hit')will begin as 0 and turn to 1 when a randomly selected number is greater than or equal to 95
  2. The 2nd checkbox (named '2ndFrame' will check the first checkbox's value at the previous frame. If this equals 1 then the 2nd checkbox will equal 1 (Thus keeping the image visible for another frame)
  3. The 3rd checkbox (named 'beenHit') checks the 2nd and 4th checkbox's value at the previous frame. If this equals 1, then the 3rd checkbox will equal 1. Further it checks if the 4'th checkbox equals 1 and will equal 1..
  4. The 4th checkbox (named 'beenHit2') will check the 3rd checkbox's value at the previous frame. If this equals 1 then the 4th checkbox will equal 1.

 

The Opacity expression will default opacity to 0 and change to 1

if either checkbox 1 or 2 are on and checkbox 3 and 4 are both off

 

My issue is that when playing back this the image will sometimes not recognise the positive previous frames and break the logic cycle leading to the image flashing multiple times. This seems to be random and sometimes fixed by refreshing or deleting cache but will come and go regardless

 

This is especially annoying as I intend to have many of the these images conver the screen which has caused majority of their expressions to not work as intended.

 

if anyone could point out any errors with my code or just this method in general or suggest an alternative method I would greatly appreciate it. I have suspicions that it is just a bug but I am a beginner with expressions and am likely missing something here.

 

I've added screenhots of the individual expressions below and a video demoonstation

Thank you in advance.

 

1st checkbox

1st checkbox.png

2nd checkbox

2nd checkbox.png

3rd checkbox

3rd checkbox.png

4th checkbox

4th checkbox.png

 

Opacity expression

Screen Shot 2022-12-05 at 12.29.40 pm.png

 

video demo

 

TOPICS
Error or problem , Expressions , Scripting

Views

412

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 04, 2022 Dec 04, 2022

I think I'd ditch the checkboxes and do something like this:

f1 = timeToFrames(inPoint);
f2 = timeToFrames(outPoint) - 1;
seedRandom(index,true);
myFrame = Math.floor(random(f1,f2));
f = timeToFrames(time);
f >= myFrame && f <= myFrame+1 ? 100 : 0

Votes

Translate

Translate
Community Expert ,
Dec 04, 2022 Dec 04, 2022

Copy link to clipboard

Copied

I think I'd ditch the checkboxes and do something like this:

f1 = timeToFrames(inPoint);
f2 = timeToFrames(outPoint) - 1;
seedRandom(index,true);
myFrame = Math.floor(random(f1,f2));
f = timeToFrames(time);
f >= myFrame && f <= myFrame+1 ? 100 : 0

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 04, 2022 Dec 04, 2022

Copy link to clipboard

Copied

Thank you very much for this I will give it a try.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

LATEST

If you really want to be sure an image is only shown once, you have to construct a loop and sort the images that have been used already into an array or something. And your math is crooked. Your effective probability is way higher than 5%, so you may want to reconsider your algorithm at the most basic level.

 

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines