Scripted Custom Attributes & DropDownLists

Scripted Custom Attributes & DropDownLists

Anonymous
Not applicable
366 Views
3 Replies
Message 1 of 4

Scripted Custom Attributes & DropDownLists

Anonymous
Not applicable
Hi Everyone,
First of all, if anything I mention here sounds inefficient please feel free point it out...

I'm working on a game and I need to pass information defined by the Art Team (in Max) out to our game engine.
So, I'm using Scripted Custom Attributes as a holders for this new info (that way everything gets saved with their associated object.)

The first test I did, was with a simple checkbox. It worked just fine.

Then, (because need to represent a list of predefined choices) I tried using a dropdownlist.
Here is the script...


-- ========================================
-- Define
-- ========================================
NewAttrs = attributes MyNewAttrs --attribID:#(0x9cf491c, 0x4c7a0cf0) --generated by genClassID()
(
parameters params rollout:MyAttrs_rollout
(
Item_Things type:#string ui:ddl_Things
)

rollout MyAttrs_rollout "My Attributes"
(
-- ----------------------------------------
-- UI Controls
-- ----------------------------------------
dropdownlist ddl_Things "Pick Thing" \
items:#("First Thing", "Second Thing", "Third Thing")
-- ----------------------------------------
-- Event Handlers
-- ----------------------------------------
on ddl_Things selected ddl_ret do
(
Item_Things = ddl_Things.items
format "Item_Things: %\n" Item_Things
)
)
)
-- ========================================
-- Assign
-- ========================================
custAttributes.add $ NewAttrs


The problem is that the selection that I make in the dropdownlist get's lost as soon as I change selections.
However, if I select the object and execute the following in the Max Script Listener...


$.Item_Things


The attribute that I defined is still correct, just not represented in the dropdownlist UI anymore.

Am I missing something simple here?
Because, no other UI Control lost track of it's data.

Thanx for any help you can provide.
-Red
0 Likes
367 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Just thinking off the top of my head but could you drop some code into an on rollout open event to force it to be the right selection.
0 Likes
Message 3 of 4

Anonymous
Not applicable
The problem I see immediately is that you are not storing your selection and since this UI is not persistant it doesnt remember anything. When you switch back to it, it will re-evaluate everything that you have defined there but it will not set anything because you are not setting anything in your initial evaluation here. What you need to do is add additional parameters and reference those when setting and updating your UI.

So add the new parameter storing your selection here.

parameters params rollout:MyAttrs_rollout
(
Item_Things type:#string ui:ddl_Things
// New parameter used to store your selection index
DropDown_Selection type:#int
)


Now reference that when updating your selection.

on ddl_Things selected ddl_ret do
(
Item_Things = ddl_Things.items
format "Item_Things: %\n" Item_Things
// Update the new Parameter
DropDown_Selection = selected
)


Depending on how you want to access this value when you load the UI and selections you can call the following.

on MyAttrs_rollout open do
(
if (DropDown_Selection != undefined) then
(
ddl_Things.selection = DropDown_Selection
)
)

0 Likes
Message 4 of 4

Anonymous
Not applicable
Thanx Randall and Dan.
That worked.
0 Likes