[Closed] Adding a default string to a dropdownlist
Hi, I need help for a script that I did. It’s pretty complete, but I have a little problem that I can’t seem to solve.
So I have a rollout and there’s multiple dropdownlists in it that lists the cameras of the current scene when you open it. But I want the dropdownlists to show ‘’ –Select Camera – ” first , and then click on it and see the cameras in the list. I need this to do a function to check if the .selected of a dropdownlist is set at ‘’ – Select Camera – ‘’ and then uncheck a checkbox. But that’s not the point. I simply want to add this string in the beginning of the dropdownlist.
So here’s a part of my script :
rollout […]
(
local cams = for i in cameras where superclassof i == Camera collect i.name
group [...]
(
dropDownList camera1 pos:[50,50] width:115 items:cams enabled:false
[…]
I tried multiple things, like : dropDownList camera1 pos:[50,50] width:115 items:#(“– Select Camera –“, cams) enabled:false
but it always says ‘’ Unable to convert: #(“Camera001”, “Camera002”) to type: String “. I tried many other things but it always shows me this. It seems it wants the names of the cameras as string but I don’t get why. If I simply put items:cams, it works, it shows the names of the cameras, but the simple fact that I want to add a string first doesn’t seem to work. I even tried to create a second array, put the string first, and then call this array instead in items, but no, same thing.
Do you have a solution for this simple task that seems so complicated right now?
Thank you
try it like this
rollout ddl_test "Drop-Down List"
(
fn collect_camera_names = for i in cameras where superclassof i == Camera collect i.name;
dropdownlist cameras_dd "Scale" items:(collect_camera_names())
on cameras_dd selected i do format "You selected '%'!
" cameras_dd.items[i]
)
createDialog ddl_test
rollout [...]
(
local cams = for i in cameras where superclassof i == Camera collect i.name
[B]insertItem " -- Select Camera -- " cams 1[/B]
group [...]
(
dropDownList camera1 pos:[50,50] width:115 items:cams enabled:false
[...]
cams and dropDownList.items are Arrays.
After some experimentation, the fastest way to do it seems to be:
cams = #(" -- Select Camera --")
join cams (for i in cameras where superclassof i == Camera collect i.name)
fastest? i don’t think it can be critical to find all cameras for 0.02 instead of for 0.01 sec …
(
delete cameras
for k=1 to 1000 do (TargetCamera())
t1 = timestamp()
for c in cameras where iskindof c camera collect c.name
format "time:%
" (timestamp() - t1)
)
---- time:13