[Aegisub related] Introduction to common user-defined functions AutoTags and their variants

The AutoTags function is used to cycle two (Group) special effect tags within the duration period, such as the blur value changes back and forth, resulting in a flicker effect. It is common in many scripts. To use this function, you first need to declare the function on the code line.

What's inside Aegisub

function AutoTags(Intervalo,Dato1,Dato2)            local RESULTADO=""     local SUERTE = 0     local CONTADOR = 0     local ARREGLO = 0                           local count = math.ceil(line.duration/Intervalo)                         ARREGLO = {Dato1,Dato2}                            for i = 1, count do               CONTADOR = i                            if Dato1 and Dato2 then                     if  CONTADOR%2 ==0 then                                    SUERTE = ARREGLO[1]                                            else                                    SUERTE = ARREGLO[2]                            end                    end                     RESULTADO = RESULTADO .."\\t(" ..(i-1)*Intervalo.. "," ..i*Intervalo.. ",\\" ..SUERTE..")"..""                      end                 return RESULTADO                                     end

In order to understand the code easily, paste the newline writing method. For Aegisub's actual use, please copy the code without newline above. The same is true for subsequent parts:

function AutoTags(Intervalo,Dato1,Dato2)            
local RESULTADO=""     
local SUERTE = 0     
local CONTADOR = 0     
local ARREGLO = 0                           
local count = math.ceil(line.duration/Intervalo)                         ARREGLO = {Dato1,Dato2}                            

for i = 1, count do               
CONTADOR = i                            
if Dato1 and Dato2 then                     
if  CONTADOR%2 ==0 then                                    
SUERTE = ARREGLO[1]                                            
else                                    
SUERTE = ARREGLO[2]                            
end                    
end                     

RESULTADO = RESULTADO .."\\t(" ..(i-1)*Intervalo.. "," ..i*Intervalo.. ",\\" ..SUERTE..")"..""                      
end                 
return RESULTADO                                     
end

Call again in template
Usage of AutoTags function in original form:
Autotags (when changing, "tag 1", "tag 2") (Figure 2)

The generated effect is shown in Figure 3

It can be observed that a reciprocating change of blur2 - > blur0 - > blur2 is generated throughout the duration of the word
If you want to use the reciprocating change between two groups of tags, note that you should use an additional \, such as AutoTags(500, "Blue2 \ FS50", "Blue0 \ fs30")
The original form of AutoTags is introduced here.

The following describes several variants generated by different requirements [AutoTags]

Variant 1

function AutoTags1(Intervalo,Dato1,Dato2,Pause)  local RESULTADO=""  local SUERTE = 0  local CONTADOR = 0  local ARREGLO = 0  local count = math.ceil(line.duration/(Intervalo+Pause))  ARREGLO = {Dato1,Dato2}  for i = 1, count do          CONTADOR = i          if Dato1 and Dato2 then                  if  CONTADOR%2 ==0 then                  SUERTE = ARREGLO[1]                  else                  SUERTE = ARREGLO[2]                  end          end          RESULTADO = RESULTADO .."\\t(" ..(i-1)*(Intervalo+Pause).. "," ..i*Intervalo+Pause*(i-1).. ",\\" ..SUERTE..")"..""  end  return RESULTADO  end

Line feed:

function AutoTags1(Intervalo,Dato1,Dato2,Pause)  
local RESULTADO=""  
local SUERTE = 0  
local CONTADOR = 0  
local ARREGLO = 0  
local count = math.ceil(line.duration/(Intervalo+Pause))  
ARREGLO = {Dato1,Dato2}  

for i = 1, count do          
CONTADOR = i          
if Dato1 and Dato2 then                  
if  CONTADOR%2 ==0 then                  
SUERTE = ARREGLO[1]                  
else                  
SUERTE = ARREGLO[2]                  
end          
end          

RESULTADO = RESULTADO .."\\t(" ..(i-1)*(Intervalo+Pause).. "," ..i*Intervalo+Pause*(i-1).. ",\\" ..SUERTE..")"..""  
end  
return RESULTADO  
end


It is used to realize the reciprocating change effect with pause time
The fourth parameter Pause is Pause time (ms)
Autotags1 (change time, "tag 1", "tag 2", pause time)

Variant 2

function AutoTags2(Intervalo,Dato1,Dato2,Delay)            local RESULTADO=""     local SUERTE = 0     local CONTADOR = 0      local ARREGLO = Layer                            local count = math.ceil(line.duration/Intervalo)                                         ARREGLO = {Dato1,Dato2}                                          for i = 1, count do               CONTADOR = i                                            if Dato1 and Dato2 then                                             if  CONTADOR%2 ==0 then                                                                    SUERTE = ARREGLO[1]                                            else                                                                    SUERTE = ARREGLO[2]                                            end                            end                                                 RESULTADO = RESULTADO .."\\t(" ..(i-1)*Intervalo+Delay.. "," ..i*Intervalo+Delay.. ",\\" ..SUERTE.. ")"..""                                  end                              return RESULTADO                                             end

Line feed:

function AutoTags2(Intervalo,Dato1,Dato2,Delay)            
local RESULTADO=""     
local SUERTE = 0     
local CONTADOR = 0      
local ARREGLO = Layer                            
local count = math.ceil(line.duration/Intervalo)                                         ARREGLO = {Dato1,Dato2}                                          

for i = 1, count do               
CONTADOR = i                                            
if Dato1 and Dato2 then                                             
if  CONTADOR%2 ==0 then                                                                    SUERTE = ARREGLO[1]                                            
else                                                                    SUERTE = ARREGLO[2]                                            
end                            
end                                                 

RESULTADO = RESULTADO .."\\t(" ..(i-1)*Intervalo+Delay.. "," ..i*Intervalo+Delay.. ",\\" ..SUERTE.. ")"..""                                  
end                              
return RESULTADO                                             
end

It is used to realize the reciprocating change effect with delay (delay relative to the line start time)

For example, you need to start 1s from the line before you need to change the effect:
AutoTags2(500, "tag 1", "tag 2", 1000)

Variant 3

function AutoTags3(Intervalo1,Intervalo2,Dato1,Dato2)  local RESULTADO=""                 local SUERTE = 0                 local CONTADOR = 0                 local ARREGLO = 0                               local count = 2*math.ceil(line.duration/(Intervalo1+Intervalo2))            local d=math.ceil((Intervalo2-Intervalo1)/count)  local t={}  ARREGLO = {Dato1,Dato2}                                                      for i = 1, count do                                   CONTADOR = i  t[1]=0  t[i+1]=t[i]+Intervalo1+(i-1)*d  if Dato1 and Dato2 then            if  CONTADOR%2 ==0 then                                                                                        SUERTE = ARREGLO[1]            else                                                                                        SUERTE = ARREGLO[2]                                                        end            end                                                             RESULTADO = RESULTADO .."\\t(" ..t[i].. "," ..t[i+1].. ",\\" ..SUERTE..")"..""                                              end                                          return RESULTADO                                                         end

Line feed:

function AutoTags3(Intervalo1,Intervalo2,Dato1,Dato2)  
local RESULTADO=""                 
local SUERTE = 0                 
local CONTADOR = 0                 
local ARREGLO = 0                               
local count = 2*math.ceil(line.duration/(Intervalo1+Intervalo2))            local d=math.ceil((Intervalo2-Intervalo1)/count)  
local t={}  
ARREGLO = {Dato1,Dato2}                                                      

for i = 1, count do                                   
CONTADOR = i  
t[1]=0  
t[i+1]=t[i]+Intervalo1+(i-1)*d  

if Dato1 and Dato2 then            
if  CONTADOR%2 ==0 then                                                                                        SUERTE = ARREGLO[1]            
else                                                                                        SUERTE = ARREGLO[2]                                                        end            
end                                                             

RESULTADO = RESULTADO .."\\t(" ..t[i].. "," ..t[i+1].. ",\\" ..SUERTE..")"..""                                              
end                                          
return RESULTADO                                                         
end

Arithmetical autotags (increase or decrease in change time)

The decrement effect is similar to the bomb timer, which is getting faster and faster
The increasing effect means that the change speed is getting slower and slower
Autotags3 (for the first change, for the final change, "tag 1", "tag 2")
The time for the first change > the time for the final change is decreasing
Final change time > first change time, which is incremental

The ASS file is attached
AutoTags.zip

github backup:
AutoTags.rar

For the time being, it's a good idea to think of such a few, equal ratio series, and two groups of time alternating changes. Welcome to add
The first post of the new year, I wish you a happy New Year

Keywords: lua

Added by Cruzado_Mainfrm on Sun, 23 Jan 2022 09:02:59 +0200