سؤال

I'm trying to write a function that calls an external script but am not having any luck with the syntax

scripts_folder = "C:\\Program Files\\Autodesk\\3ds Max 2008\\Scripts"
var script1 = "hello_world.ms"

-- use function to call scripts
callScript(script1)

-- function callScript
function callScript script =
(
getFiles scripts_folder + "\\" + script
)
هل كانت مفيدة؟

المحلول 2

Figured it out!

--- "hello_world.ms"
enter function hello =
(
print "hello the world"
)


---- another _script.ms
fileIn "hello_world.ms"

-- use function to call scripts

hello ()

It seems that fileIn works better than include

نصائح أخرى

It's good to distinct two possible solutions here:

  1. FileIn
  2. Include

fileIn will do the same as "run script" or evaluate all in the editor. It can make a function available if it's globally declared (not preferable, use as less globals as possible), if it was locally declared within that script you cannot get to it.

Include actually takes the code from that file and injects it at that point. So if you have a large script and you want to organize things a bit better you can write certain functions in a separate file and include that function when the script get executed, so that function would always accessible because it is included in that scope.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top