MaxScript: Function pointers?

MaxScript: Function pointers?

istan
Advisor Advisor
847 Views
2 Replies
Message 1 of 3

MaxScript: Function pointers?

istan
Advisor
Advisor

I have an understanding problem..

struct tTest (
  fnptr = undefined,
	
  fn tst = (
	fnptr()
  ),
  fn setfnptr func = (
	fnptr = func  
  )
)
fn TestFoo = ( print "TestFoo" )

foo = tTest()
foo.setfnptr TestFunc
foo.tst()

Why is "TestFoo" printed out twice?

 

btw, the foll. does the same:

xyx = TestFoo
xyx()

How can I be sure, the function will only be called once?

 

0 Likes
Accepted solutions (1)
848 Views
2 Replies
Replies (2)
Message 2 of 3

Swordslayer
Advisor
Advisor
Accepted solution

It's called once, every function in maxscript returns something, you could just as well write it as fn TestFoo = return (print "TestFoo"), and the return value for print is the string it prints. Maxscript listener shows the return values of everything that gets executed in global scope and of the last expression in local scope. If the function was for example fn TestFoo = (print "TestFoo"; OK), it would print the string and return OK.

0 Likes
Message 3 of 3

istan
Advisor
Advisor
ahhh and oups.. I forgot about that.. Thanks.. C++ is so much easier for me..
0 Likes