Without setting it to global, is there a way for example I can press a button, call a function, and in the function I change a lable on my UI of my script?
Announcement
Collapse
No announcement yet.
MAxscript - Access Rollout UI in a function?
Collapse
X
-
You can:Code:try(destroydialog test1);catch() rollout test1 "Group Test" width:165 height:85 ( --variable declaration local variable1 = 10 local variable2 = "Variable declared in the rollout" --function declaration fn changeText txt = ( test1.lb1.text = txt ) --ui controls label lb1 "Text" pos:[20,5] button bt1 "New Text" pos:[20,25] width:125 height:25 button bt2 "More Text" pos:[20,55] width:125 height:25 --event handlers on bt1 pressed do changeText "ABCD" on bt2 pressed do changeText "1234" ) createDialog test1
Dan Brew
-
If I stick any commands after defining the rollout, I get an error
for example any of these give an error "name expected"
renderers.current = vray()
rc=renderers.current
renderSceneDialog.close()
If I comment out any of them, then the 1st one after the comment fails
But if I put that all above the rollout, then it works fine. I have to stick it inside the rollout however, otherwise I'm back to square one with defining it in each function. Why is it not working?Kind Regards,
Morne
Comment
-
You can't put code inside a rollout body unless it is inside a function or an event handler. But there are various events like the rollout opening and closing that can trigger calling a function.Code:try(destroydialog test1);catch() rollout test1 "Group Test" width:165 height:85 ( --variable declaration local variable1 = 10 local variable2 = "Variable declared in the rollout" local rc -- declare rc as a local variable here --function declaration fn rollOpen = ( renderers.current = vray() test1.rc=renderers.current --asign here renderSceneDialog.close() ) fn rollClose = ( print "That's all folks..." ) fn changeText txt = ( test1.lb1.text = txt ) --ui controls label lb1 "Text" pos:[20,5] button bt1 "New Text" pos:[20,25] width:125 height:25 button bt2 "More Text" pos:[20,55] width:125 height:25 --event handlers on test1 open do rollOpen() on test1 close do rollClose() on bt1 pressed do changeText "ABCD" on bt2 pressed do changeText "1234" ) createDialog test1
Dan Brew
Comment
-
Yes Dan is correct. You can't execute those lines within the context of a rollout, you'd need to be in a function of the rollout to define code like that.
Also: just as good programming modularity, I would genericize the "ChangeText" function to include the control you want to use to change the text.
Code:fn changeText cntrl txt = ( if isProperty cntrl #text then cntrl.text = txt ) -- event handlers for button presses now declared like this on bt1 pressed do changeText test1.bt1 "ABCD" on bt2 pressed do changeText test1.bt2 "1234"
Colin Senner
Comment
Comment