Log in

View Full Version : Avisynth for loop GScript


wiseant
8th May 2012, 23:00
Hi

I am trying to use GScript to create a for loop

I have an avsi file that list 34 fonts, i.e.
f1 = "ARIAL" ... f34 = "Vrinda"
and another avsi file that lists 140 colors,
i.e. global aliceblue=$F0F8FF ... global yellowgreen=$9ACD32
i.e. global c1=aliceblue ... global c140=yellowgreen

In the GScript code, I would like to increment f1 to f34 - i.e. display the 34 fonts in order
The problem is how can I use the for loop to increment values from f1 to f34

I tried renaming the fonts 1 to 34 in the avsi file but this doesn't work

I have also tried other ways:
for f(i) = 1 to 34
subtitle(f(i) ...

for i = 1 to 34
subtitle("f" + i ...
or
subtitle (f+"i" ...

Can I do this without using AVSLib to create some arrays?
[I would also like to increment the textcolor and/or halocolor]

Here is my script:
fontsize=40
vwidth=98*fontsize/2
vheight=72*fontsize/2
xspace=2
yspace=fontsize + 4
textcolor1=c8
halocolor1=c120
blankclip(60,vwidth,vheight,color=$ffffff)
text=" 0123456789 AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"
GScript("""
for ( i = 1 , 34 , 1 ) {
subtitle(f3+text,x=xspace,y=i*fontsize,font=f3,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
}
""")

The script works if I just use a font value, i.e f1 ... f34

# without a for loop
#~ subtitle(f1+an,x=xspace,y=1*fontsize,font=f1,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f2+an,x=xspace,y=2*fontsize,font=f2,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f3+an,x=xspace,y=3*fontsize,font=f3,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f4+an,x=xspace,y=4*fontsize,font=f4,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f5+an,x=xspace,y=5*fontsize,font=f5,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f6+an,x=xspace,y=6*fontsize,font=f6,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f7+an,x=xspace,y=7*fontsize,font=f7,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f8+an,x=xspace,y=8*fontsize,font=f8,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f9+an,x=xspace,y=9*fontsize,font=f9,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f10+an,x=xspace,y=10*fontsize,font=f10,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f11+an,x=xspace,y=11*fontsize,font=f11,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f12+an,x=xspace,y=12*fontsize,font=f12,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f13+an,x=xspace,y=13*fontsize,font=f13,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f14+an,x=xspace,y=14*fontsize,font=f14,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f15+an,x=xspace,y=15*fontsize,font=f15,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f16+an,x=xspace,y=16*fontsize,font=f16,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f17+an,x=xspace,y=17*fontsize,font=f17,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f18+an,x=xspace,y=18*fontsize,font=f18,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f19+an,x=xspace,y=19*fontsize,font=f19,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f20+an,x=xspace,y=20*fontsize,font=f20,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f21+an,x=xspace,y=21*fontsize,font=f21,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f22+an,x=xspace,y=22*fontsize,font=f22,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f23+an,x=xspace,y=23*fontsize,font=f23,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f24+an,x=xspace,y=24*fontsize,font=f24,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f25+an,x=xspace,y=25*fontsize,font=f25,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f26+an,x=xspace,y=26*fontsize,font=f26,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f27+an,x=xspace,y=27*fontsize,font=f27,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f28+an,x=xspace,y=28*fontsize,font=f28,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f29+an,x=xspace,y=29*fontsize,font=f29,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f30+an,x=xspace,y=30*fontsize,font=f30,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f31+an,x=xspace,y=31*fontsize,font=f31,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f32+an,x=xspace,y=32*fontsize,font=f32,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f33+an,x=xspace,y=33*fontsize,font=f33,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
#~ subtitle(f34+an,x=xspace,y=34*fontsize,font=f34,size=fontsize,text_color=textcolor1, halo_color=halocolor1)

TIA

IanB
8th May 2012, 23:14
You wantf3="f"+String(i)

wiseant
8th May 2012, 23:34
Hi Ian B

If I use "f"+String(i):

GScript("""
for ( i = 1 , 34 , 1 ) {
subtitle("f"+String(i)+text,x=xspace,y=i*fontsize,font="f"+String(i),size=fontsize,text_color=textcolor1, halo_color=halocolor1)
}
""")

This doesn't change the fonts - it uses the default font Arial and it justs outputs "f1" ... "f34" sequentially without translating the f-value to the corresponding font

If I use font=f3 for example it uses Arial Italic, font=f22 it uses Palatino Linotype Italic etc.
It works if I use 34 subtitle statements - I am trying to use one subtitle statement with the for loop

-Vit-
8th May 2012, 23:51
"f22" is not the same as f22. The first is a string literal that is always just "f22", the second is a string variable containing "Arial" or "Times" or whatever. Use Eval to evaluate expressions (in this case 'read a variable out of a string')

GScript("""
for ( i = 1 , 34 , 1 ) {
subtitle("f"+String(i)+text,x=xspace,y=i*fontsize,font=Eval("f"+String(i)),size=fontsize,text_color=textcolor1, halo_color=halocolor1)
}
""")

Gavino
9th May 2012, 00:06
That's right, but he probably wants the subtitle text to show the actual font name as well, rather than "f1", etc.
GScript("""
for ( i = 1 , 34 ) {
f = Eval("f"+String(i))
subtitle(f+text,x=xspace,y=i*fontsize,font=f,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
}
""")
(Note that the for loop increment can be omitted as it defaults to 1.)

wiseant
9th May 2012, 00:10
Hi -Vit-

Thanks - that works!

Hi Gavino - You beat me to it although yours is slightly different

I am using it like this now:

GScript("""
for ( i = 1 , 34 , 1 ) {
subtitle(Eval("f"+String(i))+text,x=xspace,y=i*fontsize,font=Eval("f"+String(i)),size=fontsize,text_color=textcolor1, halo_color=halocolor1)
}
""")

or as Gavino suggested:
GScript("""
for ( i = 1 , 34 ) {
f = Eval("f"+String(i))
subtitle(f+text,x=xspace,y=i*fontsize,font=f,size=fontsize,text_color=textcolor1, halo_color=halocolor1)
}
""")

This way it outputs the font name as well as the defined text