PDA

View Full Version : Referenced variables in AviSynth?


vampiredom
31st December 2011, 03:07
Many other scripting languages allow referenced variables; so that a function can modify an existing variable – or a large variable can be passed without needing to duplicate it in memory. For example:

For a case where I'd like to modify the value of "foo", it would be convenient to be able to write [something like]:

FunctionName(\foo)

instead of:

foo = FunctionName(foo)

Is there any such way to do something like in AviSynth? I doubt there is, but I figured I'd ask the question here to see if anybody knows any way by which a function can alter a pre-defined variable.

gyth
31st December 2011, 19:31
http://avisynth.org/mediawiki/Grammar
Functions always produce a new value and never modify an existing one. What that means is that all arguments to a function are passed "by value" and not "by reference"; in order to alter a variable's value in AviSynth script language you must assign to it a new value.

If you can give an example of what you are trying to do, someone can probably come up with an equivalent solution.

vampiredom
31st December 2011, 20:15
Functions always produce a new value and never modify an existing one.
Yes, as I thought. My reason for asking is fairly obscure, so I won't bother with it more. Thanks.

redfordxx
1st January 2012, 19:42
I promised you workaround...
You might find inspiration here which is what I recently used:

global crlf=" "+Chr(10)+ Chr(13)

function SelectMultiple(string c, int n, int i){
str0=c+"_"+string(n)+"_"+string(i)+"="+c+".SelectEvery("+string(n)+","+string(i)+")"+".Subtitle(string("+string(i)+"))"+crlf
str= (i==0) ? str0 : SelectMultiple(c, n, i-1)+str0
return str
}

d1=FFVideoSource(srcfile1, pp="hb/vb:10:60", threads=1)

Eval(SelectMultiple("d1", 5, 4))
Interleave(d1_5_0,d1_5_1,d1_5_2,d1_5_3,d1_5_4)
Result of this function is n clips based on parameter n.