PDA

View Full Version : call own fn (function) from input text file


laughingLOSER
02-17-2011, 12:36 PM
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 ?

TheGrak
02-18-2011, 11:30 PM
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.

denisT
02-18-2011, 11:39 PM
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 ?

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()")

laughingLOSER
02-19-2011, 06:20 AM
I finally chose to use :

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

Thanks to you two.

CGTalk Moderation
02-19-2011, 06:20 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.