Sort the dialog options

Started by Carles, Mon 10/07/2023 10:28:44

Previous topic - Next topic

Carles

Hi!

Is there a way to sort the dialog options without changing their id?

In some dialogs I would like to change the order in which the options are displayed, but I would like to do it without changing the ID number. If I change the ID I would have to change it elsewhere in the code and it could lead to errors.

Thank you so much!

Khris

You can in theory use custom dialog rendering to change the order, yes.

But just to make sure this isn't an XY problem: if this is about adding a new dialog option above the one at the bottom (i.e. the goodbye one), simply put it above from the start. Since this solution is very obvious, your question is probably about something else though, so can you elaborate a bit? How and why exactly do you want to re-order the options?

Carles

Well, the issue is that I haven't designed the dialogues 100% from the beginning, so I am adding options during the development of the game. So in the end, the dialog options can be displayed in no very logical order.

For example, specific questions on a topic may appear first, and an introductory question last.

The issue is that changing its ID is cumbersome, because it forces you to review parts of the code where you control when these dialog options appear and disappear.

Khris

Yeah, but reordering them via custom dialog rendering is going to be much more cumbersome :)

One thing you can do is just add a bunch of blank options when you start creating a dialog so you can insert more options in the middle later. Just uncheck the "Show" options for these until you need them.

Crimson Wizard

#4
This looks like a design issue in AGS, dialogs have names, but options don't. And there's no way to conveniently reorder them anyway in the dialog editor, without copy-pasting lots of stuff (option text + script). Neither it's possible to setup their display order at runtime (automatically).

Quote from: Khris on Mon 10/07/2023 23:31:50Yeah, but reordering them via custom dialog rendering is going to be much more cumbersome

I think that reordering in dialog will be far worse, because you will have to carefully copy-paste option texts, option scripts, adjust option's checkboxes, etc. Carles already mentioned option ID references everywhere.

Reordering on display may be done by introducing mapping array: an array of ints, where index is an order of display and value is the ID of an option (or vice-versa, depending on what's more convenient).
Such array would be initialized 1:1 by default, and then adjusted depending on the dialog. This way you only need to manually configure cases where you need to change the display order.

Then script the "custom dialog options rendering" to use this array when drawing options.

EDIT: by the way, I wonder any of the existing modules support options reordering already. This sounds like something that many users would find useful.
For example, reorder options based on their "already asked" state, and so forth.

Khris

Sure, reordering them via int array is feasible.

But if you have to mostly edit the dialog script, you can do a search and replace for the number. Turning option 5 into option 7 should be relatively painless if you simply replace all occurrences of 5 with a 7.
It just requires a small bit of planning, and moving existing options into new numbers first, then putting additional options into the now free slots.

Also, if you have dozens of options in a single dialog, you might want to consider splitting it up anyway.

Carles

Thanks to both of you. I'll see how I do it.

What is clear is that dialogues should be better planned in advance.

Snarky

The Dialog Designer tool/plugin lets you reorder dialog options.

I haven't ever written any extensive dialogs in AGS, but to me it has always seemed like a must-have tool, that should really be distributed with AGS by default.

Crimson Wizard

#8
I forgot to mention, I really like to recommend declaring constants to use in script instead of plain option numbers. This is a standard method that helps avoiding editing too much script if ID changes, as you only need to edit that in one place: the constant's declaration.
Besides it clearly tells what you are doing.

What I mean is this:
Code: ags
#define DIALOG_NPC_OPT_TELLYOURNAME    1
#define DIALOG_NPC_OPT_SELLMETHEKEY    2
#define DIALOG_NPC_OPT_BYE             3

with which you can do
Code: ags
option-off DIALOG_NPC_OPT_SELLMETHEKEY
or
Code: ags
dDialog1.SetOptionState(DIALOG_NPC_OPT_SELLMETHEKEY, eOptionOff);


A somewhat safer alternative to "#define" is "enum":
Code: ags
enum DialogOptions
{
    eDlgNPC_TellYourName = 1,
    eDlgNPC_SellTheKey = 2,
    eDlgNPC_Bye = 3,
}

Carles

Great, it will be very useful for me. I'll try the Dialog Designer, but from now on I think I'll declare the constants.

SMF spam blocked by CleanTalk