[Closed] Refering to Listbox Items as button
Hello. I’m trying to create a listbox which selecting every item dose something unique. This is an example script:
global test
try(if test.dialogBar then (cui.unRegisterDialogBar test )
closeRolloutFloater test
)catch()
(
test = newRolloutFloater "Test1" 200 300
rollout unnamedRollout "Untitled1" width:150 height:150
(
listbox lbbox "cam" items:#("one","two","three") selection:1 height:3
on lbbox selected ? do
(
select $Box001
)
on lbbox selected ? do
(
select $Box002
)
)
addRollout unnamedRollout test rolledUp: false
)
MaxScript’s refrence is not clear for me. It says:
on <listbox> selected <arg> do <expr>
What <arg> shoud I put instead of question marks in the script above to refer to it’s relevent Item?
It’ll be a very big help. Thank you.
The <arg> is an argument that Max passes automatically to the “selected” Event. In this case, it contains the current selection item number.
Try this:
on lbbox selected myArg do print myArg
You can change the word myArg for any word you want.
Thank you for the reply. With your kindly explanation It’s clear now. Thanks
Or another example.
Let say you have listbox
listbox llbox "objects" items:#("box","sphere","teapot")
Now define some function for different tasks
fn doDifferentThings idx =
(
case idx do
(
1: for i = 1 to 3 do box pos:[i*30,0,0]
2: for i = 1 to 3 do sphere pos:[0,i*30,0]
3: for i = 1 to 3 do teapot pos:[0,0,i*30]
)
)
and try “on select” event
on lbbox selected idx do doDifferentThings idx
Another example for same listbox
Let say you have some coordinates array
arr = for i = 1 to 3 collect (random black white) as point3
To create object from the list on specific place (coord from array) use
on lbbox selected idx do execute (lbbox.selection + " pos:" + arr[idx] as string)