This works just fine ...
StrFormat(output_path, "%s\\%s\\%s", repository, docname, output_type);
But when I try to append a trailing back-slash like this ...
StrFormat(output_path, "%s\\%s\\%s\\", repository, docname, output_type);
I get a compile error as follows: Error (line: 514) undefined symbol 'filename'.
Here is the function's script. There are a number of string variables defined elsewhere in other functions but not this one.
string output, repository, docname;
function apGetOutputPath(string output_type, string output_path) {
// Determine if output is in document sub-directory or in output sub-directory
if (StrComp(output,".")==0) {
StrFormat(output_path,"%s\\%s\\%s\\",output, docname, output_type);
}
else {
StrFormat(output_path, "%s\\%s\\%s\\", repository, docname, output_type);
}
}
If this a bug or am I making a bone-headed error ??
Hmmm Are you sure you never used a (possibly string) variable called filename and you didn't define it?
If I comment out the two StrFormat() lines the error goes away. I guess I can try doing the same thing in an empty game to be sure.
[edit]
Ok, when I try it in a new game I get a different error message on the StrFormat() line:
Error (Line: 9) end of input reached in middle of erpression
[/edit]
Ah I know what happens now, I did a little test and I'll say it's quite possibly a bug.
The scenario is like this, that's because the string ends with \", the troublesome thing is that the "compiler" wrongly interpret that \" as you want to display a " character in the string, instead of correctly recognize the \\ first, so that " is not considered as double quotes to close the string, thus the error.
Currently I can think of 3 workarounds:
1. Add a space before ", so: "%s\\%s\\%s\\ ". I don't know what do you want for this string, but if you just want to change path or display content of the path I think adding a space to the end won't hurt.
2. Do as point 1 (add a space to the end), BUT then strip off that space character by truncating the string to one character shorter:
StrSetCharAt(output_path,StrLen(output_path)-1,0);
(See Manual entry of StrSetCharAt() for more details.
HEHE, @CJ, there's an obvious typo in this entry, you wrote StrGetCharAt() instead)
3. If you need to append a file name to the end of it anyway, just don't put the \ to the end of out_path, but put it in front of the file name and append.
Hmm yeah that's a bug - thanks for reporting it, one of Gilbert's workarounds should do the trick for now.
Thanks CJ. Thanks for your response in my other recent threads as well.