DO11 Scripting: Issue with Dialog Box

In the following Test Dialog I configured the second button to have some additional choices in a dropdown menu. I would expect that the first entry of the dropdown menu outputs choice 3 but it doesn't. Clicking the button directly correctly outputs choice 2 but when I select the first dropdown entry I also get choice 2. Is this a bug or by design?

Test Dialog Script

[code]Function OnClick(ClickData)
Set dlg = DOpus.Dlg
dlg.window = DOpus.Listers(0)
dlg.message = "Test Dialog"
dlg.title = "Test"
dlg.buttons = "Choice 1|Choice 2 + Choice 3 + Choice 4 + Choice 5 + Choice 6|Cancel"
dlg.icon = "warn"
dlg.choices = DOpus.NewVector("Choice 1", "Choice 2", "Choice 3", "Choice 4", "Choice 5")
dlg.list = DOpus.NewVector(false, false, false, false, false)
i =

If i= 1 Then
DOpus.Output "Choice 1"
End If
If i= 2 Then
DOpus.Output "Choice 2"
End If
If i= 3 Then
DOpus.Output "Choice 3"
End If
If i= 4 Then
DOpus.Output "Choice 4"
End If
If i= 5 Then
DOpus.Output "Choice 5"
End If
End Function

Looks like a bug. Choice 2 and Choice 3 both return 2, Choice 4 returns 3, Choice 5 returns 4, and so on.

We'll get that fixed in the next update. (As a workaround for now, you could add a second copy of Choice 2 to the top of the menu.)

By the way, instead of this:

Set dlg = DOpus.Dlg
dlg.window = DOpus.Listers(0)

Use this:

Set dlg = ClickData.Func.Dlg

That's better because ClickData.Func.Dlg gives you a dialog object with the correct parent window etc. all filled in for you.

Thanks for confirming the bug.

[quote] could add a second copy of Choice 2 to the top of the menu.[/quote]Yeah, that's what I did for now but I'll have to remember to change this back after the bug is fixed to have it working correctly. :slight_smile:

Thanks for the hint with ClickData.Func.Dlg. With Dopus.Dlg I had the problem that a dialog always opened behind the lister until I added the dlg.window = DOpus.Listers(0) line. Now I understand why this happened.

Actually, this may not be a bug, since all the internal Opus dialogs intentionally duplicate the button as the first entry in the menu, and it'd make sense for scripts to follow the same behaviour.

We're debating what to do here, but it may end up just being something we clarify in the documentation. Or maybe we'll add a flag to choose how it behaves.

This was changed in 11.1 beta 1, so that the button and first menu item each return separate IDs.

If you want your script to work with both versions of Opus, you can test the version information in the main DOpus object and, if it's lower than, duplicate the button as an extra menu item.