[Closed] Scope Issue
following this thread
http://forums.cgsociety.org/showthread.php?f=98&t=865613
i ended with this code
try(DestroyDialog myRollout)catch()
clearlistener()
rci = rolloutCreator "myRollout" "My Rollout"
rci.begin()
rci.addControl #button #myButton "My Button" paramStr:"width:(myRollout.Width - 8 ) align:#center"
rci.addControl #button #b2 "Button 2" paramStr:"width:(myRollout.Width - 8 ) align:#center "
rci.addControl #button #b3 "Button 3" paramStr:"width:(myRollout.Width - 8 ) align:#center"
rci.addControl #button #b4 "Button 4" paramStr:"width:(myRollout.Width - 8 ) align:#center"
rci.addControl #button #b5 "Button 5" paramStr:"width:(myRollout.Width - 8 ) align:#center"
rci.addControl #button #b6 "Button 6" paramStr:"width:(myRollout.Width - 8 ) align:#center"
rci.addControl #button #b7 "Button 7" paramStr:"width:(myRollout.Width - 8 ) align:#center"
rci.addControl #button #b8 "Button 8" paramStr:"width:(myRollout.Width - 8 ) align:#center"
rci.addControl #Checkbutton #b9 "CheckButton 9" paramStr:"width:(myRollout.Width - 8 ) align:#center highlightColor:Black"
rci.AddControl #Spinner #spn_1 "Degree1" paramStr:"width:(myRollout.Width - 8 ) align:#center"
rci.AddControl #Spinner #spn_2 "Degree2" paramStr:"width:(myRollout.Width - 8 ) align:#center "
fn Button_massDelegate the_Rollout theRolloutCreator = -- expand this function to filter the controls according to classof
(
for i in the_Rollout.Controls where classof i == ButtonControl do
(
if (i.name != "myButton" ) then -- i.name is Case Sensitive !
(
theRolloutCreator.addHandler i.name #pressed filter:on codeStr:(substituteString "X.text = @I was Clicked, my name is X@" "X" i.name)
theRolloutCreator.addHandler i.name #RightClick filter:on codeStr:"messageBox@I was Right Clicked !@ "
)
else theRolloutCreator.addHandler i.name #pressed filter:on codeStr:("MessageBox @Isn't this cool@ title:@Wow@" )
)
)
Button_massDelegate myRollout rci
createDialog (rci.end()) style:#( #style_toolwindow, #style_sysmenu)
runing the code for the first time always returns undefined error , the 2nd time … it works
while this seems to be a regular scope issue , i can’t fix it no matter what i do .
When calling this : Button_massDelegate myRollout rci
for the first time, myRollout doesn’t exist, since rci.end() hasn’t been called yet.
There is your problem.
You are calling rci.end() AFTER you have attempted to pass the rollout you were creating to the custom function you built.
“myRollout” is the variable name where the rollout creator will store the final rollout. This variable does not contain a valid value until you call rci.end() which happens later in the code.
So when you run for the first time, the function call ‘Button_massDelegate myRollout rci’ passes myRollout as undefined because it simply has not been created yet. If I understand correctly, you want to scan the previous rollout and add controls using the rollout creator based on that. In that case, you will have to just add an IF statement to only call Button_massDelegate() when myRollout is not undefined.
Btw, rolloutCreator is a script and it has a good explanation of what the functions do in its source. You can find the code under C:\Program Files\Autodesk\3ds Max 2010\stdplugs\stdscripts\baseLib\rolloutCreator.ms
Here is what the end functions does:
.end()
this function has to be called whenever all the required control and their event handler's are called. This function forms
the rollout string, evaluates it and returns the definition which can passed to createDialog and addRollout functions.
Thus, you cannot use myRollout for anything before you have called rci.end() to evaluate the rollout and produce an actual rollout class instance to be stored in the myRollout variable.
If I misunderstood your problem, please explain.
@Pier
thanks Pier , yes its not created yet , i tried desperately to use pointers thinking it might work :argh: , i even thought of closing the rollout and opening it again through the code :buttrock: but that was really nasty .
@Bobo
you understand the problem 100% right .
but calling the Button_massDelegate after the rci.End() do nothing and assigns no handlers to the controls . unfortunately , this makes the function completely useless
the whole point of this code and using the Rolloutcreator is assigning eventHandlers to different controls through compact code , much like assigning controls eventhandlers at runtime in c# , unfortunately there seem to be no solution .
if i use english wrong “and that’s a habit of mine ” , all i need is this code working from the first time with no errors
thanks Boss