Log in

View Full Version : writefile() problem inside Gscript


wiseant
6th July 2012, 06:19
Hi

I can't seem to get writefile() to work for me, probably because I am using it inside a for loop in GScript.


chapters=12
inc=frames/(chapters)

for i=0 to chapters-1
t=Eval(String(inc*i))

I then do my convert frame to time
t0=(t/24)
# for 23.976:
tms = (t*1001)/24

t1=(t0/(60*60))
s1=String(t1)+":"
if (t1 < 10) {
s1 = "0"+s1
}
t2=(t0%(60*60)/60)
s2=String(t2) +":"
if (t2 < 10) {
s2 = "0"+s2
}
t3=(t0%60)
s3=String(t3)
t4 = tms - (t1*1000*60*60) - (t2*60*1000) - (t3*1000)
if (t4 > 499) {
t3=t3+1
s3=String(t3)
}
if (t3 < 10) {
s3 = "0"+s3
}
s5=s1+s2+s3

and end up with string s5

I then tried to writefile(filename, "s5")

and all I got was the same value, the last value, 12 times instead of all 12 values?

I tried writefile(filename, "i")
and got the same result

Any ideas?

TIA

Gavino
6th July 2012, 09:36
WriteFile is a runtime (http://avisynth.org/mediawiki/Runtime_environment) filter, so evaluates its expression(s) for every frame during the frame serving phase of Avisynth. At that stage, script variables will have their final values, so that's what gets written.

What you want to use instead here is WriteFileStart (http://avisynth.org/mediawiki/WriteFileStart), which generates its output at compile-time, during script evaluation.

Incidentally, in your code:

for i=0 to chapters-1
t=Eval(String(inc*i))
Eval() is unnecessary and you can just write
t = inc*i

Also, I assume this is not a direct copy of your script as the correct syntax would be:
for (i=0, chapters-1) {
...
}

StainlessS
6th July 2012, 14:55
It would look better (formatted), if you enclosed your code in CODE tags ('#' in advanced mode menu).

Also, assume you are enclosing GScript code appropriately


GScript(""" # Begin GScript code

# Your code.

""") # End Of GScript code

wiseant
6th July 2012, 20:39
Gavino:

Yes - I only posted some of the code . . . and thanks for the tip re t = inc*i

I used

WriteFileStart(filename,"s5", append=true)

works like a charm - Thanks Gavino

Output:
00:00
09:32
19:03
28:35
38:07
47:38
57:10
01:06:42
01:16:13
01:25:45
01:35:17
01:44:48

Stainless:
Thanks for the tip - I'll have to look into using CODE tags

StainlessS
7th July 2012, 00:08
If you just want to use the code tags directly without going into advance mode (forum)
then use as start tag $CODE% and end tag $/CODE%

but replacing the '$' chars with '[' and end '%' chars with ']',
I dont know how to ESCAPE them without the forum thing altering them.

EDIT: Ie, removing '*' from below

[*CODE] your formatted stuff [*/CODE]

-Vit-
7th July 2012, 02:24
StainlessS: Going a little OT, but you can write tags without them being parsed by enclosing in a [NOPARSE] tag.

The line below is wrapped in NOPARSE:
Testy

StainlessS
7th July 2012, 02:30
Thankyou fine sir for the education, not over the top at all, some of us
need that little extra bit of help from you educators of men. :)

Really, thankyou.

EDIT: Although NOCODE might have been more obvious, not your fault and
I do not blame you at all for it. :devil: (Well maybe just a bit).