Creating a scalable Dialog System - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Creating a scalable Dialog System (
/showthread.php?tid=634767)
Creating a scalable Dialog System -
CheatForSpeed - 26.05.2017
Hi, I wonder if there's already a best practice for a scalable (meaning easily readable / maintainable) Dialog system apart from the usual approach:
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
if (dialogid == DIALOG_TELEPORT) {
...
}
return 1;
}
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:
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
if (dialogid == DIALOG_TELEPORT) onDialogTeleport(playerid, response, listitem, inputtext[]);
...
return 1;
}
But how should it be done anyway?
I really like the whatever-cmd approach with pseudo-tagged functions like
PHP код:
CMD:pn(playerid, params[]) { ... }
...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.
PHP код:
enum DIALOG_IDS {
DIALOG_TELEPORT,
...
}
new DIALOG_NAMES[DIALOG_IDS];
DIALOG_NAMES[DIALOG_TELEPORT] = "teleport";
...
The dream
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, ...)
If you have any idea I'd love to discuss about all the options.
Thx.
Re: Creating a scalable Dialog System -
Kane - 26.05.2017
https://sampforum.blast.hk/showthread.php?tid=475838
Is this what you're looking for?
Re: Creating a scalable Dialog System -
CheatForSpeed - 27.05.2017
Quote:
Originally Posted by Arthur Kane
|
Yes it is, thanks!
Sadly the links in the thread are broken; I asked in the thread to provide working ones, or do you got the include laying around somewhere?
Re: Creating a scalable Dialog System -
YouHack - 27.05.2017
Enjoy:
https://github.com/Awsomedude/easyDialog/releases
Re: Creating a scalable Dialog System -
Vince - 27.05.2017
Search for it on GitHub. Edit: late.