reForm
03-12-2006, 03:20 PM
I've been having problems with calling functions from within a rollout. Please can someone help me work out what I am doing wrong! :)
Whats weird is, that the function works fine.... then after working on other bits of code, the function stops working, apparently for no good reason :(
for example:
the function:-
fn editmat mat =
(
try
(
if (mat != undefined) do
(
if mateditor.isopen() == false do
(
mateditor.open ()
)
activeslot = medit.getActiveMtlSlot()
setMeditMaterial activeSlot mat
)
)
catch (messagebox "There was a problem putting the material to the editor")
)
called from the following rollout
local CreateMatRollout
fn CreateMatRollout myCollection =
( MLister.vrayMatRC = rolloutCreator "vrayMatsRollout" "Materials"
MLister.vrayMatRC.begin()
fn CreateControls =
(
MLister.vrayMatRC.addControl #Button (("MatEdit" + MLister.count as string) as name) "E" \
paramStr:(" offset:[70,-18] align:#left width:10 height:13 filter:on tooltip:\"Edit material in material editor\" ")
MLister.vrayMatRC.addHandler (("MatEdit" + MLister.count as string) as name) #'pressed' \
codeStr:("editMat MLister.matindex[" + MLister.count as string + "]")
)
createControls
)
Yet, if I use the same code from the function instead of calling the function, ie
MLister.vrayMatRC.addHandler (("MatEdit" + MLister.count as string) as name) #'pressed' \
codeStr:("try(if (MLister.matindex[" + MLister.count as string + "] != undefined) do (if (mateditor.isopen() == false) do (mateditor.open ())\n local activeslot = medit.getActiveMtlSlot()\n setMeditMaterial activeSlot MLister.matindex[" + MLister.count as string + "]))catch (messagebox @There was a problem putting the material to the editor@)")
The button works fine!
Can anyone explain what I am doing wrong? I know its something to do with scope of variables, or the way the function is called.... but I just can't figure it out.
The error I am getting is :-
-- Error occurred in MMatEdit12.pressed()
-- Frame:
-- editmat: undefined
>> MAXScript Rollout Handler Exception: -- Type error: Call needs function or class, got: undefined <<
The above code is incomplete, so dont try to copy-paste to test it. If you want to view the full code, please download it from here.
http://www.reformstudios.com/03-resources/MatLister/VRayMatList_0_30_simple.ms (http://www.reformstudios.com/03-resources/MatLister/VRayMatList_0_30_simple.ms)
Thanks in advance for any assistance.
Whats weird is, that the function works fine.... then after working on other bits of code, the function stops working, apparently for no good reason :(
for example:
the function:-
fn editmat mat =
(
try
(
if (mat != undefined) do
(
if mateditor.isopen() == false do
(
mateditor.open ()
)
activeslot = medit.getActiveMtlSlot()
setMeditMaterial activeSlot mat
)
)
catch (messagebox "There was a problem putting the material to the editor")
)
called from the following rollout
local CreateMatRollout
fn CreateMatRollout myCollection =
( MLister.vrayMatRC = rolloutCreator "vrayMatsRollout" "Materials"
MLister.vrayMatRC.begin()
fn CreateControls =
(
MLister.vrayMatRC.addControl #Button (("MatEdit" + MLister.count as string) as name) "E" \
paramStr:(" offset:[70,-18] align:#left width:10 height:13 filter:on tooltip:\"Edit material in material editor\" ")
MLister.vrayMatRC.addHandler (("MatEdit" + MLister.count as string) as name) #'pressed' \
codeStr:("editMat MLister.matindex[" + MLister.count as string + "]")
)
createControls
)
Yet, if I use the same code from the function instead of calling the function, ie
MLister.vrayMatRC.addHandler (("MatEdit" + MLister.count as string) as name) #'pressed' \
codeStr:("try(if (MLister.matindex[" + MLister.count as string + "] != undefined) do (if (mateditor.isopen() == false) do (mateditor.open ())\n local activeslot = medit.getActiveMtlSlot()\n setMeditMaterial activeSlot MLister.matindex[" + MLister.count as string + "]))catch (messagebox @There was a problem putting the material to the editor@)")
The button works fine!
Can anyone explain what I am doing wrong? I know its something to do with scope of variables, or the way the function is called.... but I just can't figure it out.
The error I am getting is :-
-- Error occurred in MMatEdit12.pressed()
-- Frame:
-- editmat: undefined
>> MAXScript Rollout Handler Exception: -- Type error: Call needs function or class, got: undefined <<
The above code is incomplete, so dont try to copy-paste to test it. If you want to view the full code, please download it from here.
http://www.reformstudios.com/03-resources/MatLister/VRayMatList_0_30_simple.ms (http://www.reformstudios.com/03-resources/MatLister/VRayMatList_0_30_simple.ms)
Thanks in advance for any assistance.
