Log in

View Full Version : Scripting 101


t_2
4th June 2004, 00:08
Could someone tell me why this script fails?

I have a feeling it has something to do with how I default the clips. I want to write a function to act on an indefinate number of clips, so am going to write it for 64 clips, assuming that there will never be that many. What am I doing wrong???




a=blankclip(color=$227722, length=10)
b=blankclip(color=$551f51, length=10)

function join(clip c1,clip c2,clip c3)
{
Assert(Exist(c1)==true, """ no input clips""")
Assert(Exist(c1)==true && Exist(c2)==true, """You need at least 2 input clips""")
Return((Exist(c2)==true && Exist(c3)==false)? c1+c2: c1+c2+c3)
}

Join(a,b)

scharfis_brain
4th June 2004, 00:16
you have to define your variables this way:

function join(clip c1,clip "c2",clip "c3")

stickboy
4th June 2004, 11:18
Originally posted by t_2
Could someone tell me why this script fails?
a=blankclip(color=$227722, length=10)
b=blankclip(color=$551f51, length=10)

function join(clip c1,clip c2,clip c3)
{
Assert(Exist(c1)==true, """ no input clips""")
Assert(Exist(c1)==true && Exist(c2)==true, """You need at least 2 input clips""")
Return((Exist(c2)==true && Exist(c3)==false)? c1+c2: c1+c2+c3)
}
Join(a,b) What scharfis_brain said. Optional parameters need double-quotes around their names.
Splice/UnalignedSplice already do what you want your Join function to do.
Exist takes filenames (strings) as arguments, not clips. You probably meant to use Defined instead.
No need to use triple double-quotes.
Comparisons to true or false are redundant. Operators such as Exist or Defined already return boolean values. Does Defined(x) == true improve readability? How about (Defined(x) == true) == true, ad infinitum?
Checking whether c1 and c2 are defined needs to be done only once in your function. That is, you could do something such as:function Join(clip "c1", clip "c2", clip "c3")
{
Assert(Defined(c1), "No input clips")
Assert(Defined(c2), "You need at least 2 input clips")
return Defined(c3) ? (c1 + c2 + c3) : (c1 + c2)
}

t_2
4th June 2004, 16:54
@scharfis_brain: Thanks, I missed that!

@Stickboy: Quote: Does Defined(x) == true improve readability?

No, I just didn't understand. Thanks for "Defined". I read the manual but just didn't get it. Now I do. All this was a big help, I've finally got my real functions working. Thanks, again.

Question: Is there some command that returns the current frame number? I know the program keeps track of it from clip.info

Wilbert
4th June 2004, 17:02
It's accesible in the conditional filter environment:

ScriptClip("subtitle(string(current_frame))")

See

http://www.avisynth.org/index.php?page=ConditionalFilter

stickboy
4th June 2004, 17:34
Or, if you just want to display the current frame number in the video, there's ShowFrameNumber.

t_2
4th June 2004, 22:14
@Stickbox: Thanks, more for the future in animate type functions.

@Wilbert: That sure was burried deep in the bowels of the liturature. I couldn't find an explicit reference to "current_frame". It was, however used in a script.

This script works:

video=blankclip
Return video.Subtitle(String(video.width))

But this doesn't:

video=blankclip
Return video.Subtitle(String(video.current_frame))

Also, it seems that with ScriptClip the paramater of the evaluated function can only be a function of current_frame. Otherwise, why won't this script work?

BlankClip.ScriptClip("subtitle("frame =" + string(current_frame))")

Wilbert
4th June 2004, 23:54
Like I said you can only use it in the conditional filter environment (because it's a per frame property), that is with filters like ConditionalFilter, ScriptClip, etc.

Conditional filtering is very difficult if you just started with AviSynth. But I suggest you try to understand the relevant docs (ie the link I posted).

Try this:

a = "frame = "
BlankClip.ScriptClip("subtitle(a + string(current_frame))")

I'm not sure why your script doesn't work. Maybe someone else knows?

stickboy
5th June 2004, 05:16
Originally posted by t_2
Otherwise, why won't this script work?

BlankClip.ScriptClip("subtitle("frame =" + string(current_frame))")The frame= part isn't part of the string. You have a string next to a (undefined) variable name, and that's not legal syntax.

I'm going to assume you want the "frame= part to be part of the string, including the double-quote. In this case, you do need to use triple quote marks so that you can embed quotes within it:
ScriptClip("""subtitle("frame =" + string(current_frame))""")