Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
For bucle donde cada valor se distribuye correctamente

Tengo un bucle for en el que quiero distribuir una cierta cantidad de palabras con la misma longitud en una línea de tiempo.

Tengo variables que me dan la duración de cada texto, el inicio de donde se generarán las palabras y el final.

 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; } }

El error viene al final, como se ve en la imagen. La palabra del final (resaltada en blanco) tiene menos longitud que la anterior, y la penúltima palabra tiene más longitud que todas las demás.

Soy consciente de que esto no es un problema de sintaxis, sino un problema matemático que parece que no puedo resolver. Gracias por adelantado

EDITAR: Encontré la respuesta y actualicé la sintaxis para que coincida.

La palabra al final (resaltada en blanco) tiene menos longitud que la anterior, y la penúltima palabra tiene más longitud que todas las demás palabras

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Actualicé la sintaxis para que coincida con el código correcto.

Resulta que el problema era que el espacio para cada palabra no se calculaba correctamente.

Lo hice funcionar calculando el inicio y el final de cada sección haciendo esto:

 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);

Luego, usé la diferencia del principio y el final y lo dividí por la longitud de las palabras.

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

Espero que ayude a alguien por ahí.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!