Notifications
Clear all

[Closed] Weird Function Issue

I have a function (A) that I am trying to call inside of another function (B)

FunctionA has one parameter which I am supplying.

When I run the script, maxscript keeps saying that FunctionA is undefined.

It is not undefined because I am calling it inside other functions and it works just fine there.
I am at a loss what to do.

FunctionB works fine if I don’t call functionA inside it.

I have double triple quadruple checked my spelling (including copy/pasting the name)

Any ideas anybody?

Thanks in advance,

Rhys.

8 Replies

In order for function A to be called, I believe it needs to be above function B. Is this presently the case in your script?

I don’t see why it needs to be above…

Despite that, I have tried moving it above. And it still doesn’t work.

 eek

Recursive fns that are called inside another fn dont work ive found too.

fn testB a =
(
fn testA n =
(
n + 20
)
10 + a
)

testB (testA 20) – this i dont think will work because testA is not declared.

if you put them in a struct for example:

struct testStruct
(
fn testA a =
(
a + 20
),

fn testB b =
(
testA + b
)
)

Now this wont work unless you instance the struct:

testC = testStruct()
testC.TestB 20

this still wouldnt work as ‘a’ is an undeclared variable from the first function unless you supply it as a varible in the struct

struct testStruct
(
a = 20,

fn testA a
(
a + 20
),

fn testB
(
testA + 20
)

)

testC = testStruct()

now nesting fns work:

fn testA
(
fn testB n
(
20 – n
)

100.0/ (testB 12.4)

)

This is more along the lines of what I have:

fn FunctionA theVar =
(
myVarOne = 3
myVarTwo = myVarOne + theVar
return myVarTwo
)

fn FunctionB =
(
theVar = 5
anotherVar = FunctionA theVar <<<<<<<<<<<<
return anotherVar
)

fn FunctionC =
(
BlahBlah = FunctionA 7
return BlahBlah
)

I get the error “FunctionA is undefined” at the indicated place!
Where FunctionC works absolutely fine.

Rhys.

Does the example code you posted work for you?
It works here.

Make sure you have not mistyped the name of the function

what if you call it with brackets?

anotherVar = FunctionA (theVar)

I think that you should call it like:
anotherVar = (FunctionA theVar)

One of the consequences of the slightly odd syntax in maxscript in my opinion.

Thankyou all of for all your help.
I had a gap in my understanding and it turns out that erilaz was right and I had an ordering problem

Once I re-ordered all the functions it just began working.

I didn’t realise that functions had to be in a certain order but I sure do now!

Thanks once again for everybodies helpful comments.

Rhys.