[Closed] Pickbutton Problem
hi, im new to scripting and decided to make a wheel rotation script as my first attempt but i soon encounterd a problem:
i created a utility interface which allows the user to select his car body and four wheels via ‘pickbuttons’
but i wanted to create a message to show if the user inadvertently picked geometry already assigned to another pickbutton.
eg. if the user picked box01 via the ‘pick car body’ button and then tried to pick the same box when using the ‘pick front left wheel’ button a warning message would appear.
yet although i thought i worded it correctly , no message box appears!
any pointers would be appreciated, thanks.
here is the script so far:
[size=3][color=white]utility[/color][/size] wheelscript “Wheel Rotation”
(
fn testclass obj = superclassof obj == GeometryClass
pickbutton car “Pick Car” filter:testclass
pickbutton frontleft “Pick front left wheel” filter:testclass
pickbutton frontright “Pick front right wheel” filter:testclass
pickbutton backleft “Pick back left wheel” filter:testclass
pickbutton backright “Pick back right wheel” filter:testclass
On car picked obj do
( if obj==frontleftobj then
messagebox “pick unassigned object please”
else
carobj=obj
)
On frontleft picked obj do
( if obj==carobj then
messagebox “pick unassigned object please”
else
[size=3]frontleftobj=obj
)
)
[/size]
carobj and frontleftobj are not declared outside of the event handers, thus they become local variables to the event handler functions and are “invisible” to the other handlers.
You should add the line
local carobj,frontleftobj
to the utility just before the FN definition. You can add the variable names of all other objects you might want to add in the future.
A better way though would be to avoid picking objects via the filter function you already have…
utility wheelscript "Wheel Rotation"
(
local theCarArray = #()
fn testclass obj = superclassof obj == GeometryClass and findItem theCarArray obj == 0
pickbutton car "Pick Car" filter:testclass
pickbutton frontleft "Pick front left wheel" filter:testclass
pickbutton frontright "Pick front right wheel" filter:testclass
pickbutton backleft "Pick back left wheel" filter:testclass
pickbutton backright "Pick back right wheel" filter:testclass
on car picked obj do theCarArray[1]=obj
on frontleft picked obj do theCarArray[2]=obj
on frontright picked obj do theCarArray[3]=obj
on backleft picked obj do theCarArray[4]=obj
on backright picked obj do theCarArray[5]=obj
)
Now, if you have picked the car body already, the mouse and Select By Name dialog will skip the object and not even provide the user with a chance to pick the wrong object.
You could also display the name of the picked object on the button:
utility wheelscript "Wheel Rotation"
(
local theCarArray = #()
fn testclass obj = superclassof obj == GeometryClass and findItem theCarArray obj == 0
pickbutton car "Pick Car" width:160 filter:testclass
pickbutton frontleft "Pick front left wheel" width:160 filter:testclass
pickbutton frontright "Pick front right wheel" width:160 filter:testclass
pickbutton backleft "Pick back left wheel" width:160 filter:testclass
pickbutton backright "Pick back right wheel" width:160 filter:testclass
on car picked obj do (theCarArray[1]=obj; car.text = obj.name )
on frontleft picked obj do (theCarArray[2]=obj; frontleft.text = obj.name )
on frontright picked obj do (theCarArray[3]=obj; frontright.text = obj.name )
on backleft picked obj do (theCarArray[4]=obj; backleft.text = obj.name )
on backright picked obj do (theCarArray[5]=obj; backright.text = obj.name )
)
Thank you very much bobo, you are a legend!
No doubt as i progress with this script ill have more to ask.