Creating a scalable Dialog System
#1

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(playeriddialogidresponselistiteminputtext[]) {
  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(playeriddialogidresponselistiteminputtext[]) {
  if (
dialogid == DIALOG_TELEPORTonDialogTeleport(playeridresponselistiteminputtext[]);
  ...
  return 
1;

But how should it be done anyway?
I really like the whatever-cmd approach with pseudo-tagged functions like

PHP код:
CMD:pn(playeridparams[]) { ... } 
...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(playeridresponselistiteminputtext[]) {
  ...
}
// somewhere in a function / etc.
ShowPlayerDialod(playeridDIALOG_TELEPORT, ...) 
If you have any idea I'd love to discuss about all the options.
Thx.
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=475838

Is this what you're looking for?
Reply
#3

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?
Reply
#4

Enjoy:
https://github.com/Awsomedude/easyDialog/releases
Reply
#5

Search for it on GitHub. Edit: late.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)