View Full Version : do...until-loop
TKC
15th April 2006, 20:02
How can I create a loop in an AVS like that (Perl):
do {
blabla();
$i++;
} until ($i==10)
Thanks,
TKC
runtime? —
Global i=0
XXXSource("blabla.xxx")
blala()
ScriptClip(Last,"blabla(bla=i)",after_frame=true) #runtime
FrameEvaluate(Last,"i=i+1",after_frame=true)
Richard Berg
15th April 2006, 22:23
If you want to run at script-interpretation time instead --
for(0, "<=10", "+1",
\"""
blabla()
""")
http://forum.doom9.org/showthread.php?t=106880&highlight=array+loop
stickboy
16th April 2006, 07:01
How can I create a loop in an AVS like that (Perl):
do {
blabla();
$i++;
} until ($i==10)Exactly why do you want to do this? A lot of people often think they want loops like in imperative programming languages but haven't really wrapped their minds around AviSynth's more functional nature. There's usually a better way.
But anyhow, the typical on-script-load way is to write a recursive function.
Richard Berg
16th April 2006, 17:50
Note that I completely agree with stickboy -- the constructs I created in that thread were great for mental masturbation, but almost never show up in my working scripts. I tend to write a ton of helper functions as I work, but the only function in my entire plugin/avsi directory to use a procedural loop is:
# Given a list of numbers, returns the one closest to the input
#
# PARAMETERS:
# "input" : number to compare against
# "numbers" : comma-delimited list of numbers to search
#
#
function FindClosest(val input, string numbers)
{
# parse string into array
Dim("rates", 0, 0) # empty is ok - we'll fill it manually
Fill(rates, numbers)
# need Length2 here since we filled manually
global g_len = rates.Length2
global g_minDelta = input - rates0
global g_input = input
for(1, "<g_len", "+1",
\"""
global g_minDelta = abs(g_input - rates.deref(i)) < abs(g_minDelta)
\ ? g_input - rates.deref(i)
\ : g_minDelta
""")
ret = input - g_minDelta
return input.IsInt ? int(ret) : ret
}
Even this would be more naturally expressed in functional style, if AVS supported Haskell-style lists or similar.
It's no accident that Ben works in language research (http://research.microsoft.com/~simonpj/papers/not-not-ml/index.htm).
danpos
16th April 2006, 17:59
@Richard Berg / Stickboy
[OFF-TOPIC]
Hi, fellas! Could you take an eye in this thread (http://forum.doom9.org/showthread.php?p=814095#post814095) . I guess that you can to give some clues because of you're great AVISynth scripters.
Thanks in advance,
[/OFF-TOPIC]
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.