[Closed] Global Functions?
Im trying ot make a global function for a callback.
However i do have some issues when I try various methods
Method 1
global myAnimate
fn myAnimate = ()
Method 2
global myAnimate()
fn myAnimate = ()
What am i doing wrong here?
method 1 seems to work fine here
but shouldn’t the following be possible?
global fn = test()
Of course not.
Actually, you probably meant
(
global fn test = (print "Test")
)
This does not work because the Parser expects a name of a variable after the reserved keyword global, but finds another reserved keyword fn. So it says:
[b][color=Red]-- Syntax error: at function, expected name
[/color][/b]
The correct way is (as you discovered yourself)
(
global test
fn test = (print "Test")
)
hrmm i think my problem arrises from a rollout opening another rollout… Is there a way i can access the rollout
eg rollout1.rollout2.myfunction() ?
when i use a global with any kind of braketing it causes errors…
When i dont use the brakets i get the following error
>> MAXScript Callback script Exception: – Type error: Call needs function or class, got: undefined <<
actually, i can’t even remember what i meant haha
maybe i shouldn’t allow myself to post at certain times of the day and in certain situations
does it need to be in brakets?
like you have posted
(
gloabal myfunction
fn myfunction(print “boo”)
)
then to call the function as per normal just use myfunction() ?
Thanks
The brackets put the whole code in local scope. So without the GLOBAL myfunction, the functions would become local. This was to show that the GLOBAL declaration actually does anything.
Without the brackets, ANYTHING would become implicitly global anyway…
ok here is rougly my code… I Still get the error. I still think it may be related to my rollout launching a rollout, where this function resides…
>> MAXScript Callback script Exception: – Type error: Call needs function or class, got: undefined <<
global fnRadiosityLighting
fn fnRadiosityLighting =
(
print “boo!”
)
on mybutton pressed do
(
sceneRadiosity.radiosity.Reset true true
callbacks.addScript #radiosityProcessDone “fnRadiosityLighting()” id:#radiosityDone
sceneRadiosity.radiosity.Start()
)