CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 03-12-2006, 04:20 PM   #1
reForm
Expert
portfolio
Patrick Macdonald
CG Artist
reForm Studios
London, United Kingdom
 
Join Date: Apr 2005
Posts: 574
Why do my functions not work?

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:-
Code:
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

Code:
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
Code:
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


Thanks in advance for any assistance.
__________________
Patrick Macdonald
Lighting TD : http://reformstudios.com
Developer of Mission Control
, the spreadsheet editor for 3ds Max

Last edited by reForm : 03-12-2006 at 04:22 PM.
 
Old 03-13-2006, 01:21 AM   #2
reForm
Expert
portfolio
Patrick Macdonald
CG Artist
reForm Studios
London, United Kingdom
 
Join Date: Apr 2005
Posts: 574
As usual, after posting the question on cgtalk.... I fix the problem soon after!

Looks like I needed to make the function part of the struct...

ie after the function, I needed to have :-

MLister.curmatoff = curmatoff

Can anyone explain the reason for this? Why do I need to pass functions into the struct? I am a bit confused about the processes going on here that dictate that I need to do this.

Anyway, I'm glad to finally have fixed the problem, and learnt a little more about the dark arts of maxscript!
__________________
Patrick Macdonald
Lighting TD : http://reformstudios.com
Developer of Mission Control
, the spreadsheet editor for 3ds Max
 
Old 03-13-2006, 01:22 AM   #3
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:09 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.