Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Dusk on Sat 07/08/2004 17:09:52

Title: dialog system extension and troubles with #define
Post by: Dusk on Sat 07/08/2004 17:09:52
Hi all,
I was starting to code a dialog subsystem/extension using globalInts and
dialog_request... I thought that using #define and some tricks I could get a readable and powerful generic system to handle particular dialog situations. The game I'm working on with my team is getting big and we need an easy way to implement complex dialogs...

I explain my idea... I set a bunch of

#define DLG_CONDITION 1
#define DLG_ACTION 2
#define DLG_WHAT_ROOM 3
// 1,2,3... free globalints
...

to store "parameters"
and others costants like

#define DLG_BEEN_IN_ROOM_CONDITIONAL 1
#define DLG_PLAYERHASGOTOBJECT_CONDITIONAL 2
#define DLG_GOT_OBJECT1 3
#define DLG_ADDPHRASE 4
...


and I insert a generical dialog_request working this way:


function dialog_request(int what) {
  int ok = 0;
  int action = GetGlobalInt(DLG_ACTION);
//check what condition
if (what==DLG_BEEN_IN_ROOM_CONDITIONAL) {
if (HasPlayerBeenInRoom(GetGlobalInt(DLG_WHAT_ROOM))) ok = 1;
} else if (what==DLG_PLAYERHASGOTOBJECT_CONDITIONAL)
...
} else if (what==...) {
...
}
//end conditions
if  (ok!=1) return; //condition not satisfied, do nothing
// else check what action is requested and perform it
if (action==DLG_ADDPHRASE) {
...
} else if (action==DLG_GIVEOBJECT) {
...
}
}


The idea was that this way I could have written in the dialog scripts something like


set-globalint DLG_ACTION DLG_ADDPHRASE
set-globalint DLG_WHATPHRASE 12
set-globalint DLG_WHATROOM 14
run-script DLG_BEEN_IN_ROOM_CONDITIONAL


and I think that's not so bad in reading/writing and once written a good set of condition/actions it would be useful (and of course released here :)).

By the way, I just began to try a basic action and immediately got stuck: it seems that in dialog scripts #defines are ignored.

I tried to put #defines in the script header, and also to copy them in the dialog script... no errors, but not working. Replacing with numbers in the dialog scripts works, so I concluded that #defines aren't supported in the dialog scripts. But I hope that I'm wrong... any ideas? :(

Obviously, writing something like

set-globalint 1 4
set-globalint 2 12
set-globalint 4 14
run-script 1


is not really readeable/useful.

As usual, sorry for my terrible english and goodbye! :)

Dusk

Title: Re: dialog system extension and troubles with #define
Post by: Pumaman on Sat 07/08/2004 20:07:36
#defines are part of the script language, not part of the dialog script -- so you are correct, they are not supported in the dialog script.
Title: Re: dialog system extension and troubles with #define
Post by: Kweepa on Sat 07/08/2004 21:00:25
You might be better off writing your own dialog system.
Each dialog would be a separate function which is called from the dialog interface when you select an option.

if (currentDialog == D_TALKTOERIKESTRADA)
{
  dialogFunctionErikEstrada(dialogOption);
}
else
if (currentDialog == D_TALKTOBRIANBOITANO)
{
  dialogFunctionBrianBoitano(dialogOption);
}
etc

You'd need an array of dialog structures which contained the conversation options and a function to initialize them all.

Then you can use script language instead of dialog script.

Not easy but once you have the basic setup going it could work out cleaner.

Hmmm, can AGS work with function pointers? *Goes to check*
Title: Re: dialog system extension and troubles with #define
Post by: Dusk on Sat 07/08/2004 21:23:50
uhm ok... thanks Pumaman, Steve - I think I'll try to write my dialog system from scratch. Alternatively, I could write dialog scripts using my constants and then run a find/replace with some text editor (a kind of hand-made preprocessing :))

By the way I'll think about writing the complete system, maybe a tree-based implementation different from the usual AGS dialog treatment.
I recently read about unofficial struct support, and it should give the possibility, in conjuction with arrays, of making something of really flexible. Good, good  :D

Thanks again, bye
Title: Re: dialog system extension and troubles with #define
Post by: Kweepa on Sun 08/08/2004 06:57:23
Sounds like a plan!
Title: Re: dialog system extension and troubles with #define
Post by: Pumaman on Sun 08/08/2004 13:58:14
In terms of writing your own dialog system, would having some lower-level functions such as:

ShowDialogOptions(int topic)
RunDialogOption(int topic, int option)
GetDialogOptionText(int topic, int option)

be useful to people? That way, you could still use the built-in dialogs and set them up in the editor, but you could run them in a custom fashion. Or would that still not allow the level of customizability you're after?
Title: Re: dialog system extension and troubles with #define
Post by: Proskrito on Sun 08/08/2004 14:46:11
i would find them useful with the addition of a function that returns the number of dialog options in a topic (maybe this is what you meant with 'ShowDialogOptions'? )
Title: Re: dialog system extension and troubles with #define
Post by: Pumaman on Sun 08/08/2004 16:16:45
Sounds sensible, I'll add it to my list.
Title: Re: dialog system extension and troubles with #define
Post by: Dusk on Sun 08/08/2004 18:29:21
Quote from: Pumaman on Sun 08/08/2004 13:58:14
In terms of writing your own dialog system, would having some lower-level functions such as:

ShowDialogOptions(int topic)
RunDialogOption(int topic, int option)
GetDialogOptionText(int topic, int option)

Uhm what would ShowDialogOptions(int topic) do differently from RunDialog(int topic)?
By the way they should come handy, especially RunDialogOption I think.

By the way, IMveryveryHO, the problem with complex dialogues is that you can have to check many conditions and adjust options, and the only way to do it is using dialog_request(int parameter).

Improvements (taken from the todo list) could be
* "if globalint 5 == 10" support for conditionals in dialog scripts
* dialog_request_ex(int topic, int parameter)  pass in the topic number

The first would give a quick way to check conditions directly in the dialog script, while the second will make dialog_request_ex readable ad usable in large games too, cause you could organize it by topic and in a standard scheme, and call

#define OBJECTCHECK 1
#define ALREADYTALKEDCHECK 2
//etc...
function dialog_request_ex(int topic, int parameter) {
  if (topic==1) {
      if (parameter == OBJECTCHECK) {
          //in topic 1, if you have money turn on the option "I wanna buy a cake"
          if (character[GetPlayerCharacter()].inv[MONEY]>0) SetDialogOption(topic,2,1);
          else SetDialogOption(topic,2,0);
     } else  if (parameter == ALREADYTALKEDCHECK) {
            ....
     }
   } else if (topic==2) {
    ...
   }
}

At the start of each dialog you could then call the needed run-scripts

@S
run-script 1
run-script 2
....

to setup options.
But at this point it would probably be easier to support defines in the dialog-scripts, coming back to the origin of this thread  :)

I can understand that this stuff is probably low-priority, no problem... I'll get what I want in some way : )
thankyou again

(uhm I think I write too much, btw :D)