Better way to access dropdownlist values in Maxscript,

Hello,

I’ve been having a few issues with the dropdownlist menu item in Maxscript. Basically, I have various values (mainly float values) in a dropdown list that the user can select. If I use basically “<dropdownlist>.selection” I get the number of the item in the array, so far example if I had something like this,
(random example)

#("1.0", "5.5", "10.4", "20.8", "50.5","100.1", "200.05")

and I want to get the value contained in the selection, using “.selection” returns the number of the item, but not the actual value it contains (so instead of 100 I would get 6 instead of 100).

To “fix” this I just use a case statement which works fine, but seems a bloated way of doing things.

So is this a syntax/logic error on my part, or something else?

Thanks for your time. :slight_smile:

Jonathan,

Use the index returned by selection to access the data from the items array of the dropdownlist.

	dropdownlist test "test" items:#("A","B","C","D","E","F","G","H","I","J") height:6 
	button btn_test "get selection"
	
	on test selected i do
	(
		print	test.items[i]
	)
	
	on btn_test pressed do
	(
		print test.items[test.selection]
	)

or you can use the .selected property of the drop down list control which returns the value of the selected item and not its index.

cheers,
o

Thanks for the responses. Cannot believe it was that simple, just needed “selected” instead of selection. Woot! (works if you cast it as an integer or float, i.e.- “~.selected as integer”)

Thanks again.