Why do my functions not work?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 03 March 2006   #1
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:-
fn editmat mat =
 			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"
	 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 + "]")	

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.


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 March 2006 at 04:22 PM.
Old 03 March 2006   #2
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 March 2006   #3
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

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
Society of Digital Artists

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

All times are GMT. The time now is 12:08 PM.

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