maxscript 中的范围变量
Scope variable in maxscript
如何将变量从一个作用域传递到另一个作用域?我不能预先声明它,因为只有当用户选择对象时才定义对象。实际上这段代码失败了,因为它试图读取在另一个范围内定义的局部变量。
在伪代码中:
1.pick一个对象
2.copy所选对象
实际代码:
macroScript Variables
category:"Whosebug"
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"
on pass pressed do (
newObj = copy objectPicked
print newObj
)
)
createDialog Roll 300 80
)
在这种情况下,它真的很简单,因为您可以访问 pickButton 的对象 属性:
rollout Roll "Scopes"
(
pickButton pickObj "Pick object" autoDisplay:true
button pass "Pass the variable"
on pickObj picked objectPicked do
if isValidNode objectPicked do
pickobj.tooltip = "You picked " + objectPicked.name
on pass pressed do
(
local newObj = copy pickobj.object
print newObj
)
)
createDialog Roll 300 80
但即使没有它,您也可以将节点分配给可访问范围内的变量:
rollout Roll "Scopes"
(
local pickedObj
pickbutton pickobj "Pick object" autoDisplay:true
button pass "Pass the variable"
on pickobj picked objectPicked do
if isValidNode objectPicked do
(
pickedObj = objectPicked
pickobj.tooltip = "You picked " + objectPicked.name
)
on pass pressed do
(
local newObj = copy pickedObj
print newObj
)
)
createDialog Roll 300 80
如何将变量从一个作用域传递到另一个作用域?我不能预先声明它,因为只有当用户选择对象时才定义对象。实际上这段代码失败了,因为它试图读取在另一个范围内定义的局部变量。
在伪代码中:
1.pick一个对象 2.copy所选对象
实际代码:
macroScript Variables
category:"Whosebug"
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"
on pass pressed do (
newObj = copy objectPicked
print newObj
)
)
createDialog Roll 300 80
)
在这种情况下,它真的很简单,因为您可以访问 pickButton 的对象 属性:
rollout Roll "Scopes"
(
pickButton pickObj "Pick object" autoDisplay:true
button pass "Pass the variable"
on pickObj picked objectPicked do
if isValidNode objectPicked do
pickobj.tooltip = "You picked " + objectPicked.name
on pass pressed do
(
local newObj = copy pickobj.object
print newObj
)
)
createDialog Roll 300 80
但即使没有它,您也可以将节点分配给可访问范围内的变量:
rollout Roll "Scopes"
(
local pickedObj
pickbutton pickobj "Pick object" autoDisplay:true
button pass "Pass the variable"
on pickobj picked objectPicked do
if isValidNode objectPicked do
(
pickedObj = objectPicked
pickobj.tooltip = "You picked " + objectPicked.name
)
on pass pressed do
(
local newObj = copy pickedObj
print newObj
)
)
createDialog Roll 300 80