Skip to main content
ethanwhipple
Known Participant
October 28, 2022
Question

Use different expression if checkbox is checked.

  • October 28, 2022
  • 3 replies
  • 181 views

Hello! Title says it all. I am trying to use a different equation on a text layer if a checkbox is checked, allowing me to have "Millions" as a visible number (as sliders are limited to 1,000,000). I put the equation I am using below.

Any help is greatly appreciated!

 

`sSize = comp("YouTube Goal 1").layer("CONTROLS").effect("NUM START")("Slider");
eSize = comp("YouTube Goal 1").layer("CONTROLS").effect("NUM END")("Slider");
t = comp("YouTube Goal 1").layer("CONTROLS").effect("PROGRESS")("Slider");
v = Math.floor(linear(t, 0, 100, sSize, eSize));{

if(comp("YouTube Goal 1").layer("CONTROLS").effect("MILLION")("Checkbox") == 1){
n = v/1000;
m = v/1000000;
if (v < 1000) v;

else if (v == 1000) Number(n) +"K";
else if (v > 1000 && v <99999) Number(n).toFixed(1) + "K";

else if (v == 100000) Number(n) +"K";
else if (v > 100000 && v <999999) Number(n).toFixed(0) + "K";

else if (v == 1000000) Number(m) +"M";
else if (v > 999999) Number(m).toFixed(1) + "M"

} if(comp("YouTube Goal 1").layer("CONTROLS").effect("MILLION")("Checkbox") == 0){

n = v/1000;
m = v/1000000;
if (v == 1000) Number(n) +"M";
else if (v > 1000 && v <99999) Number(n).toFixed(1) + "M";

} else {
value;
}`

 

Thanks,

Ethan

This topic has been closed for replies.

3 replies

Mylenium
Legend
October 29, 2022

Yeah, now that I'm back on my computer I see the errors, too. Was going to suggest Dan's code, anyway, but Rick already took care of it. 🙂

 

Mylenium

Community Expert
October 29, 2022

There are numerous errors in the expression. You have a bunch of nonsensical if/else arguments and the math doesn't make sense. 

 

Borrowing from Dan Ebberts Universal Counter, this might do what you want to do. 

 

 

 

numDecimals = 2;
commas = true;
beginCount = effect("Start")("Slider");
endCount = effect("End")("Slider");

t = effect("Progress")("Slider");
s = linear (t, 0, 100, beginCount, endCount).toFixed(numDecimals);

if (commas){
  decimals = "";
  if (numDecimals > 0){
    decimals = s.substr(-(numDecimals + 1));
    s = s.substr(0,s.length - (numDecimals + 1));
  }
  outStr = s.substr(-s.length, (s.length-1)%3 +1);
  for (i = Math.floor((s.length-1)/3); i > 0; i--){
    outStr += "," + s.substr(-i*3,3);
  }
  v = outStr + decimals;
}else{
  s;
}

if(effect("Checkbox Control")("Checkbox") == 0){
	v + " K";
}
else{
	v + " M"
}

 

 

 

Mylenium
Legend
October 28, 2022

And what exactly is the problem (aside from the code being inefficient and inelegant) ? On first glance it should work...

 

Mylenium