ekanderson Posted March 15, 2009 Share Posted March 15, 2009 Function xx(string file1, string file2, x, string xx) private string xx ="?" Private string something =file1 Private string something_else =file2 ? xx +file1 +" " + file2 always prints "? file1 file2" even if passed the optional argument as a string variable. Is there a way to pass a string as an optional argument to a sequence function???? Link to comment Share on other sites More sharing options...
AzeoTech Posted March 16, 2009 Share Posted March 16, 2009 which is the optional argument? xx? I think you are using a different language's syntax for this, or perhaps an older version of DF. If there's something still in the manual that says otherwise, please tell me. Anyhow, with newer releases of DF, doing private string xx="?" will simply assign xx to "?" whether it is passed in or not. I think you want this: if (isempty(xx)) private string xx = "?" endif Link to comment Share on other sites More sharing options...
ekanderson Posted March 17, 2009 Author Share Posted March 17, 2009 don't know what page, but this pulled from help, but it used a numeric var. 1) You want to create a function with optional arguments. In this case, you will want to put all the arguments in the function declaration, and then declare the optional ones as privates initialized with their default values. Note that all the optional arguments must be at the end of the argument list: function IncrementBy(x, by) private by = 1 return(x+by) In this example, IncrementBy(4) will return 5 because "by" is optional and defaults to 1. IncrementBy(4,2), however, will return 6 because "by" was specified. Link to comment Share on other sites More sharing options...
AzeoTech Posted March 17, 2009 Share Posted March 17, 2009 That is wrong and we're fixing it now. It was true back in 5.40 or so, but we changed it so that: private x = 1 will set x to 1 whether x was declared or not. It used to be that x would only be set to 1 if x wasn't declared, which is why it used to work. Use the new method I showed before. Link to comment Share on other sites More sharing options...
ekanderson Posted March 17, 2009 Author Share Posted March 17, 2009 with 5.79A, your code works! The joys of documentation. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.