Notifications
Clear all

[Closed] Problem with include

I have this function in D:\3dsmax9\Scripts\inclFunc.ms

fn printFunc =
  (
  print "print something"
  )

Now I’m including this file and try to call printFunc

clearlistener()
  (
  incPath = "D:\\3dsmax9\\Scripts\\" 
  include (incPath + "inclFunc.ms")
  printFunc()
  )

Executing this script throws error
– Compile error: include expected filename string
– In line: include (
However this works fine:

clearlistener()
  (
  include "D:\\3dsmax9\\Scripts\\inclFunc.ms"
  printFunc()
  )

Am I doing something wrong? Is there some kind of workaround, because I use include in few different scripts and it is much more convenient to keep path in one global variable.

5 Replies

try this…

clearlistener()
(
incPath = “D:\3dsmax9\Scripts\”
include ((incPath + “inclFunc.ms”) as string)
printFunc()
)

Already did. Gives same error.

Based on what it says in the reference I did some tests and it seems that the include function only requires a filename, without a path, as it automatically looks for the script in the scripts directory. In your case:

clearlistener()
  (
  include "inclFunc.ms"
  printFunc()
  )

You can also account for the ms file being in a folder within the scripts directory by saying something like:

clearlistener()
  (
  include "myDirectory\\inclFunc.ms"
  printFunc()
  )

If the file you are looking to include is not in the scripts directory I guess you’ll need to use fileIn which does require a full path

Could be because include doesn’t allow for use of variables, as mentioned in the Maxscript reference :

[left]include “filename_string”
[/left]
[left][left]This is a compile-time construct, therefore the file name specification must be a string literal, and not a variable or an expression.[/left][/left]
[left][left]”[/left][/left]
[left][left] [/left][/left]
[left][left]A filein should work better for this purpose, though filein would execute the contents of the concerned file in global scope.[/left][/left]

Thanks for your help, fileIn seems to be working fine.