[Closed] Changing prefix of a variable by press a button?
Dear forum,
I want to change prefix of a variable by type the prefix in editText
then press Enter button.Then this variable(changeable prefix) used by a function.
example: prefix_Foot (i can change R_Foot or L_Foot) then used by this script
rollout test "Test Rollout" width:170
(
editText prefix "prefix var:" fieldWidth:50 across:2
button enterBtn "Enter" offset:[20,0]
button FootRigBtn "Foot Rig"
on enterBtn pressed do
(
------- change prefix of a variable in the button below (or in some function)
)
on footRigBtn pressed do
(
fn FootRigFn=
(
----variables are here
----prefix of variable change as the Enter button pressed
prefix_Foot=$.rotation.controller
)
)
)
createdialog test()
is this possible? or there’s alternative way?
you could dynamically create variable names, but for what you seemingly need, why not just create two radiobuttons (one for Left and one for Right), and simply use two variables to go with those?
That might be a strange question, but why would you want to change a variable’s name?
Possibly the wrong approach for something like this, much simpler to use a pair of UI checkbuttons, Left and Right and use something like –
if left.checked then
(
do left_foot business
)
else do right_foot business
if you catch my drift.
Another option, if you’re only getting nodes, would be to use the GetNodeByName function:
rollout ct_rollout_out "options"
(
dropdownlist my_list "objects" items:#("L_","R_")
button FootRigBtn "Foot Rig"
)
on footRigBtn pressed do
(
My_Object = GetNodeByName (ct_rollout_out.my_list.selected + "_foot")
--continue rest of function using My_Object when referring to your object
)
Or something like that.
Create 2 button?i did it.
But I want to shortening my script (i think it’s too long ,about 50 lines for each button)
also if i modifying L_Foot, i have to modifying R_Foot.time consuming.
Why do i need to change prefix?
cause in some line i accessing Controller object name’s (e.g. R_Foot_CTRL)
also i think it will be useful in the next scripting job, if i can change prefix variable.
to deutch_light:
not yet try your method but thanks for reply.
What i think maybe it will change algorithm my script.
Is that because you are doing something like
$R_Foot_Ctrl.position.controller
? If so, you would probably optimise it more by calling a function with the foot node as an argument. this would work if you are duplicating the code for each button.
ie –
fn footbiznizz thefoot =
(
thefoot.pos = blahblahblah etc
)
on leftfoot pressed do footbiznizz L_Foot_Ctrl
on rightfoot pressed do footbiznizz R_Foot_Ctrl
@ LoneRobot:
Thank you,
i will try it. Not this week,cos i have a lot of work in my study.
i think it’s one good way ha…ha…you’re nice.
i will reply if this method working or not.