Notifications
Clear all

[Closed] call own fn (function) from input text file

Hi all,
first time i ask a question on a forum. Have been earning maxscript in a empirical way for two years (with success at least for what i needed to do).I m now stuck (and it s been two weeks) on a simple problem.
How can i call my own function from a text file.
I mean : i can readvalue or readexp any maxscript function.
But when i have a fn like :
fn whatthehell a =
(

)
and in my text file : whatthehell a; it returns undefined.
is it a limitation of input files or is there a trick ?

3 Replies
1 Reply
(@denist)
Joined: 2 years ago

Posts: 0

if the function that you want to call is not defined you have to evaluate definition of this function first, and evaluate the function after:


/*
fn testPrint = print "test"
testPrint()
*/
execute ("fn testPrint = print \"test\"")
execute ("testPrint()")

I’m not 100% sure I understand what you are wanting to do, but…

  1. You can write a function to a text file, load the text file in, and then use ‘execute’ to read the string as maxscript.
  2. You can also do a fileIn() to run .ms files.

I finally chose to use :

read = readchars data_file n
if read = = “n chars” do
(
myownfunction a
)

Thanks to you two.