View Full Version : How to Write a String inside GScript?
gwendolien
4th July 2013, 10:49
I can't get a proper output trying to separate printing variables inside GScript.
I Tried """ ";" """ but that results in an error
Many other attempts result in nothing being written at all...
or in ' unexpected character ";" ' being printed.
What is the proper way to print separation characters inside GScript?
StainlessS
4th July 2013, 11:35
GScript("""
S="ABCDE"
""")
Gavino
4th July 2013, 11:44
GScript() is similar to ScriptClip() in that it has a string parameter which provides the script to be executed, so the same rules apply inside the GScript() string as would inside ScriptClip().
Normally, you use triple-quotes as the outer string delimiter. This then allows normal string literals (with single quotes) to be used inside the string. The problem comes when you also need triple quotes inside the GScript string itself - is that your case?
There are a number of ways round that.
For example, assign the string to a variable outside GScript and use the variable name inside instead of the string literal.
s = """A string containing "another string" """
GScript(""" ... # here s can be used, eg
Subtitle(s)
""")
Another way is to use GImport() instead of GScript().
This reads the script (or part script) from a file instead of a string, so doesn't need the outer delimiters at all.
gwendolien
4th July 2013, 12:12
Thanks Stainlesss/Gavino.
I should have added, I think, that the GScript is called from another ScriptClip call.
so:
clip.ScriptClip("""LumaDiff_alt(....
Function LumaDiff_alt(.....
GScript("""
.
.
WriteFileStart(clip, "file.txt", String(var1), """ ";" """, String(b=var2)...
results in unexpected character ";" being written to the file.
Defining the separator outside the GScript call as:
S=""" ";" """ does give the wanted separator character between the vars.
Thanks!!
StainlessS
5th July 2013, 10:03
gwendolien,
I think I've seen Vampiredom use something like 7 double quotes to embed triple quotes, enclosing single double quote strings,
(perhaps in MpegAutoIndex script).
Anybody know what the rules are for multiply embedded strings ?
Gavino
5th July 2013, 11:46
Anybody know what the rules are for multiply embedded strings ?
If a string literal starts with a single quote character ("), the string itself cannot contain a quote character - any quote character found is taken as the closing delimiter, so cannot be part of the string.
If it starts with triple quotes ("""), the closing delimiter is the next set of triple quotes that is not followed by a further quote. So with this form, the string itself can contain quote characters. It can even include three or more consecutive quotes if these occur at the end of the string.
So, with """strange""""""" (seven quotes at end), the string itself ends with four quote characters.
Note that chr(34) can also be used to produce a quote character without actually writing one in the script.
For example, triple quotes can be put around a string s with this code:
q = chr(34)
q3 = q+q+q
s = q3+s+q3
StainlessS
6th July 2013, 03:23
Truly a fountain of knowledge, thank you sir G.
gwendolien
14th July 2013, 17:52
Truly a fountain of knowledge, thank you sir G.
I second this wholeheartedly!!
Forensic
15th July 2013, 18:25
Speaking for all forensic video analysts, AVIsynth would be little more than a just a side line tool without the wisdom of this amazing doom9 community, especially the generous innovations and guidance from both Gavino and StainlessS. Thank you.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.