26.05.2017, 01:54
Hi, I wonder if there's already a best practice for a scalable (meaning easily readable / maintainable) Dialog system apart from the usual approach:
Why not?
I don't like that way of solving this problem as there's so much (unnecessary) code in the callback itsself. Either because all the behavior is inside the if blocks or there's a call to an external function for every dialogid. For example:
But how should it be done anyway?
I really like the whatever-cmd approach with pseudo-tagged functions like
...but I didn't find a good way to link an id from an enum to a named function. Is there maybe another way, so that the dialog name is only defined at one place?
I guess it would be possible with an enum and an array like that, but then I can use the traditional way and call a function as well.
The dream
For me the dream scenario would be to have a dynamic Dialog router inside OnDialogResponse so I just have to write:
If you have any idea I'd love to discuss about all the options.
Thx.
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
if (dialogid == DIALOG_TELEPORT) {
...
}
return 1;
}
I don't like that way of solving this problem as there's so much (unnecessary) code in the callback itsself. Either because all the behavior is inside the if blocks or there's a call to an external function for every dialogid. For example:
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
if (dialogid == DIALOG_TELEPORT) onDialogTeleport(playerid, response, listitem, inputtext[]);
...
return 1;
}
I really like the whatever-cmd approach with pseudo-tagged functions like
PHP код:
CMD:pn(playerid, params[]) { ... }
I guess it would be possible with an enum and an array like that, but then I can use the traditional way and call a function as well.
PHP код:
enum DIALOG_IDS {
DIALOG_TELEPORT,
...
}
new DIALOG_NAMES[DIALOG_IDS];
DIALOG_NAMES[DIALOG_TELEPORT] = "teleport";
...
For me the dream scenario would be to have a dynamic Dialog router inside OnDialogResponse so I just have to write:
PHP код:
enum {
DIALOG_TELEPORT
}
DIALOG:teleport(playerid, response, listitem, inputtext[]) {
...
}
// somewhere in a function / etc.
ShowPlayerDialod(playerid, DIALOG_TELEPORT, ...)
Thx.