Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
For loop where each value is distributed correctly

I have a for loop where I want to distribute a certain number of words with the same length across a timeline.

I have variables that give me the duration for each text, the start of where the words will spawn, and the end.

var wordArray = [];
for (t = 0; t < words.length; t++) {
//This generates the textbox
wordArray[wordArray.length] = currentComp.layers.addText(words[t]);
 if (t == 0) {
        //This makes the first textbox appear in the start
        wordArray[wordArray.length - 1].inPoint = start;
        //This makes the first textbox have the length with the value that divides it by the number of words
        wordArray[wordArray.length - 1].outPoint = wordArray[wordArray.length - 1].inPoint + textTime;
    //Here I am trying to make them all evenly distributed by multiplying the divided duration for the number of words that are already existing
    } else if (t < words.length - 2) {
        wordArray[wordArray.length - 1].inPoint = start + textTime * (wordArray.length - 1);
        wordArray[wordArray.length - 1].outPoint = end - textTime * (wordArray.length - 1);
    } else {
        //This is here to make the last word stop at the end of the text duration.
        wordArray[wordArray.length - 1].inPoint = start  + textTime * (wordArray.length - 1);
        wordArray[wordArray.length - 1].outPoint = wordArray[wordArray.length - 1].inPoint + textTime;
    }

}

The error comes in the end, as seen in the image.The word in the end (highlighted in white) has less length than the previous, and the second to last word has more length than all the other words.

I'm aware this isn't a syntax issue, rather a maths issue that I can't seem to figure out. Thanks in advance

EDIT: Found the answer and updated the syntax to match it.

The word in the end (highlighted in white) has less length than the previous, and the second to last word has more length than all the other words

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I updated the syntax to match the correct code.

Turns out that The issue was that the gap for each word wasn't being calculated correctly.

I got it to work by calculating the start and the end of each section by doing this :

var startDurationString = timeCalc[0].split(":");
    var finalStartDurationString = startDurationString[1] + ":" + startDurationString[2] + ":" + startDurationString[3];
    var startDuration = currentFormatToTime(finalStartDurationString, currentComp.frameRate);
    var endDurationString = timeCalc[1].split(":");
    var finalEndDurationString = endDurationString[1] + ":" + endDurationString[2] + ":" + endDurationString[3];
    var endDuration = currentFormatToTime(finalEndDurationString, currentComp.frameRate);

Then, I used the difference of the start and the end and divided by the length of the words.

durationForEachText = (endDuration-startDuration) / numberOfWords.length;

Hope it helps anyone out there.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda