Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography



Maxunderground news unavailable

Old variable scope question. How do you guys approach it?
show user profile  3joez
I usually adopt cheesy tricks to pass a variable from one local scope (like using globals and so on) to another scope.
I know that if a variable hasn't been declared before, it is implicitly declared in a local fashion at the moment it's used.
Long story short, here's an example of an object that needs to be passed from one local scope to another local scope:


macroScript Variables
category:"Maxforums"
toolTip:""

(

rollout Roll "Scopes"
(
pickbutton pickobj "Pick object"
on pickobj picked objectPicked do if isValidNode objectPicked do pickobj.tooltip = "You picked " + objectPicked.name

button pass "Pass the variable, come on"
on pass pressed do (

newObj = copy objectPicked
print newObj

)
)
createDialog Roll 300 80

)



How would you guys approach the problem?
Photobucket

read 240 times
9/29/2016 11:02:25 AM (last edit: 9/29/2016 2:54:01 PM)
show user profile  Garp
Something like




read 219 times
9/30/2016 2:32:24 PM (last edit: 9/30/2016 2:32:24 PM)
show user profile  3joez
Thansk Garp. Now I understand.
But generally, how can you tell when a scope starts and ends?
Photobucket

read 216 times
9/30/2016 2:49:41 PM (last edit: 9/30/2016 2:49:41 PM)
show user profile  Garp
In short, the parentheses.
For more details, there's a whole topic in the ref. Look for 'scope of variables'.




read 203 times
10/1/2016 1:39:42 AM (last edit: 10/1/2016 1:39:42 AM)
show user profile  3joez
Thx
Photobucket

read 194 times
10/1/2016 7:42:42 AM (last edit: 10/1/2016 7:42:42 AM)
#Maxforums IRC
Open chat window


Support Maxforums.org