Author Topic: How to avoid duplication in your dialogue files  (Read 5548 times)

Offline Kulyok

  • Global Moderator
  • Planewalker
  • *****
  • Posts: 6253
  • Gender: Female
  • The perfect moment is now.
How to avoid duplication in your dialogue files
« on: July 02, 2007, 04:41:45 AM »
It is interesting that sometimes two .d files(two already coded dialogue files) with the same amount of content might weigh a rather different amount of kilobytes; sometimes it is 30kb versus 100kb.

There are three major groups of reasons for that:
- comments;
- old, traditional style of coding;
- duplicating.

With comments, it is more or less clear. Learning from someone else's code is always welcome, and when this someone else provides useful tips in their comments, it is even better. Space? Oh, who cares. As long as it's not a novel.

Style of coding might be a matter of personal taste, but just as an example:
Code: [Select]
IF ~Global("VariableTrigger","GLOBAL",2)~ THEN BEGIN StartDialogue
SAY ~I must have a word with you, <CHARNAME>.~
IF ~~ THEN REPLY ~Of course. What do you want?~ DO ~SetGlobal("VariableTrigger","GLOBAL",3)~ GOTO State1
IF ~~ THEN REPLY ~Not now.~ DO ~SetGlobal("VariableTrigger","GLOBAL",3)~ GOTO State2
END

IF ~~ THEN BEGIN State2
SAY ~Oh, all right then.~
IF ~~ THEN EXIT
END
Code: [Select]
IF ~Global("VariableTrigger","GLOBAL",2)~ StartDialogue
SAY ~I must have a word with you, <CHARNAME>.~
++ ~Of course. What do you want?~ DO ~SetGlobal("VariableTrigger","GLOBAL",3)~ + State1
++ ~Not now.~ DO ~SetGlobal("VariableTrigger","GLOBAL",3)~ + State2
END

IF ~~ State2
SAY ~Oh, all right then.~
IF ~~ EXIT
END
- if you want to save space and make your dialogue more easy to read, the second one might be a good alternative.


But the main point of this thread is duplication. How does it happen? How to avoid it? What are its major faults and advantages? And why am I writing this thing?

The last question is very easy to answer. When I read .d files, it's much harder to read a text with many duplications, and when I encounter a typo in such a text, I have to replace it not once, but many times - and "mass replace" is not always an option. And while I don't encounter duplication in my own code often, community efforts, such as BG1 NPC and RE, are ripe with repetitions.

So! Why and how does duplication happen?

There are two major groups of reasons:
1) long sequences with a different first state;
2) same replies in different states.

1) Long sequences with a different first state.

Example:
(This is just a chunk of text from one of RE components done by me; it's quite different in the mod.)
Code: [Select]
IF ~~ State1
SAY ~It is all history now. But as you wish.~
= ~Bodhi is the most intelligent and brutal foe I have ever had. Her attacks almost always were taking us by surprise, and very few survived them.~
= ~We still do not know where most missing members are. Bodhi's kind never disposed of the bodies - on the contrary, more than once the victims were left on the street, bloodless. So, she must have needed them alive for some sinister purpose.~
= ~From what I gather, the theory that Bodhi is, in fact, Irenicus' ally is not impossible. He blasted half of the Promenade apart, and she nearly destroyed you single-handedly. You should be on your guard.~
= ~And this is all I have to say on the subject. Perhaps we should talk of something else.~
IF ~~ EXIT
END

IF ~~ State2
SAY ~Indeed? I am surprised. But as you wish.~
= ~Bodhi is the most intelligent and brutal foe I have ever had. Her attacks almost always were taking us by surprise, and very few survived them.~
= ~We still do not know where most missing members are. Bodhi's kind never disposed of the bodies - on the contrary, more than once the victims were left on the street, bloodless. So, she must have needed them alive for some sinister purpose.~
= ~From what I gather, the theory that Bodhi is, in fact, Irenicus' ally is not impossible. He blasted half of the Promenade apart, and she nearly destroyed you single-handedly. You should be on your guard.~
= ~And this is all I have to say on the subject. Perhaps we should talk of something else.~
IF ~~ EXIT
END

IF ~~ State3
SAY ~Perhaps. It remains to be seen.~
= ~Bodhi is the most intelligent and brutal foe I have ever had. Her attacks almost always were taking us by surprise, and very few survived them.~
= ~We still do not know where most missing members are. Bodhi's kind never disposed of the bodies - on the contrary, more than once the victims were left on the street, bloodless. So, she must have needed them alive for some sinister purpose.~
= ~From what I gather, the theory that Bodhi is, in fact, Irenicus' ally is not impossible. He blasted half of the Promenade apart, and she nearly destroyed you single-handedly. You should be on your guard.~
= ~And this is all I have to say on the subject. Perhaps we should talk of something else.~
IF ~~ EXIT
END

Basically, the same chain is posted three times. Are there any benefits, any at all? Doesn't appear so.

Now, imagine, what happens to the dialogue file, if such a chain is duplicated, say, up to four or six times, and such happens over a dozen times throughout the dialogue? A possible headache, and a possible source of confusion. And, should typos be found, trouble.

The solution is, of course, very simple:

Code: [Select]
IF ~~ State1
SAY ~It is all history now. But as you wish.~
IF ~~ + State4
END

IF ~~ State2
SAY ~Indeed? I am surprised. But as you wish.~
IF ~~ + State4
END

IF ~~ State3
SAY ~Perhaps. It remains to be seen.~
IF ~~ + State4
END

IF ~~ State4
SAY ~Bodhi is the most intelligent and brutal foe I have ever had. Her attacks almost always were taking us by surprise, and very few survived them.~
= ~We still do not know where most missing members are. Bodhi's kind never disposed of the bodies - on the contrary, more than once the victims were left on the street, bloodless. So, she must have needed them alive for some sinister purpose.~
= ~From what I gather, the theory that Bodhi is, in fact, Irenicus' ally is not impossible. He blasted half of the Promenade apart, and she nearly destroyed you single-handedly. You should be on your guard.~
= ~And this is all I have to say on the subject. Perhaps we should talk of something else.~
IF ~~ EXIT
END

... and our dialogue file becomes smaller and simpler.

2) Same replies in different states.

Example:
(Just some random text.)
Code: [Select]
IF ~~ State1
SAY ~Oh, I don't know. I might disagree. What do you think?~
++ ~I think I agree.~ + Reply1
++ ~I think I disagree.~ + Reply2
++ ~I have no opinion on the matter.~ + Reply3
++ ~Stop it; this is boring.~ + Reply4
END

IF ~~ State2
SAY ~I agree with him, of course. What do you think?~
++ ~I think I agree.~ + Reply1
++ ~I think I disagree.~ + Reply2
++ ~I have no opinion on the matter.~ + Reply3
++ ~Stop it; this is boring.~ + Reply4
END

IF ~~ State3
SAY ~Mmm... I don't really know. What do you think?~
++ ~I think I agree.~ + Reply1
++ ~I think I disagree.~ + Reply2
++ ~I have no opinion on the matter.~ + Reply3
++ ~Stop it; this is boring.~ + Reply4
END

Does it have any benefits? Well, it might make the dialogue look more "flowing" this way. But does it? Several states, same replies. Same links. Writing (slightly) different replies and new states could indeed make this dialogue flow better and look better, but then there wouldn't be any repetitions to talk about, would there?

So, what to do? There are two solutions here. The first one would be separating each state with replies into "unique part" and "common part", and attaching all replies to the common part:

Code: [Select]
IF ~~ State1
SAY ~Oh, I don't know. I might disagree.~
IF ~~ + State4
END

IF ~~ State2
SAY ~I agree with him, of course. ~
IF ~~ + State4
END

IF ~~ State3
SAY ~Mmm... I don't really know.~
IF ~~ + State4
END

IF ~~ State4
SAY ~What do you think?~
++ ~I think I agree.~ + Reply1
++ ~I think I disagree.~ + Reply2
++ ~I have no opinion on the matter.~ + Reply3
++ ~Stop it; this is boring.~ + Reply4
END

But what happens if no common part is present? Then I would invent one. After all, these are the same replies, so they can well be the replies to the same question.

Example:
Code: [Select]
IF ~~ State1
SAY ~Perhaps. Why don't we hear our guest? <CHARNAME>?~
++ ~I think I agree.~ + Reply1
++ ~I think I disagree.~ + Reply2
++ ~I have no opinion on the matter.~ + Reply3
++ ~Stop it; this is boring.~ + Reply4
END

IF ~~ State2
SAY ~I agree with him, of course. What do you think?~
++ ~I think I agree.~ + Reply1
++ ~I think I disagree.~ + Reply2
++ ~I have no opinion on the matter.~ + Reply3
++ ~Stop it; this is boring.~ + Reply4
END

IF ~~ State3
SAY ~Mmm... I don't really know. But it's not that I care. And you? Do you agree, my friend?~
++ ~I think I agree.~ + Reply1
++ ~I think I disagree.~ + Reply2
++ ~I have no opinion on the matter.~ + Reply3
++ ~Stop it; this is boring.~ + Reply4
END

Now, "What do you think?" and "Let us hear our guest." or "What do you think, <CHARNAME>?" could work as a "common state". Or, indeed, it could be something new, or a sum of two replies. And here we have our solution:

Code: [Select]
IF ~~ State1
SAY ~Perhaps. Why don't we hear our guest?~
IF ~~ + State4
END

IF ~~ State2
SAY ~I agree with him, of course.~
IF ~~ + State4
END

IF ~~ State3
SAY ~Mmm... I don't really know. But it's not that I care.~
IF ~~ + State4
END

IF ~~ State4
SAY ~What is your opinion, <CHARNAME>? Do you agree?~
++ ~I think I agree.~ + Reply1
++ ~I think I disagree.~ + Reply2
++ ~I have no opinion on the matter.~ + Reply3
++ ~Stop it; this is boring.~ + Reply4
END

There are plenty of examples in various mods, and in each example, a common state exists - it just takes the author to find the best solution. I would also recommend jcompton's "The Looping Branch Lovetalk Technique".

Dialogue structures in IE are very flexible, though, unlike it is with certain other games, it is impossible to put replies in a separate state. Still, as shown in this thread, there are ways and means, and it is up to each individual writer whether to use these opportunities or ignore them.

Offline jastey

  • Global Moderator
  • Planewalker
  • *****
  • Posts: 1524
  • Gender: Female
Re: How to avoid duplication in your dialogue files
« Reply #1 on: March 27, 2022, 02:16:09 AM »
I'll add this here because it gives new possibilities to give variety to dialogues without having the player click through x extra lines - which can become tedious real quickly, especially if it's a repretitive dialogue like a greeting. Instead of making different texts extra lines and leading them back to the same state with the reply options, you can also use COPY_TRANS to add the same reply options from one state of your own mod to different states. CamDawg made an example here which originally dealt with randomising greeting lines and reply options, but I am linking it here for how it uses the COPY_TRANS to make sure the first two dialogue states have the same reply options without having to paste them twice:
Code: [Select]
BEGIN CDTEST

  IF ~RandomNum(2,1)~ Intro1 SAY ~Greetings! I have an incredible offer for you.~
    IF ~RandomNum(3,1)~ THEN REPLY ~No thanks.~ EXIT
    IF ~RandomNum(3,1)~ THEN REPLY ~Yes.~ GOTO QuestExpo
    IF ~RandomNum(3,2)~ THEN REPLY ~Short answer: no. Long answer: noooooooooo.~ EXIT
    IF ~RandomNum(3,2)~ THEN REPLY ~Yes, please.~ GOTO QuestExpo
    IF ~RandomNum(3,3)~ THEN REPLY ~Ah, hell naw.~ EXIT
    IF ~RandomNum(3,3)~ THEN REPLY ~Ooh, tell me, tell me, tell me!~ GOTO QuestExpo
  END

  IF ~RandomNum(2,2)~ Intro2 SAY ~Hello freinds! Would you like to hear about my exciting quest?~ 
    COPY_TRANS CDTEST Intro1
  END

  IF ~~ QuestExpo SAY ~(exciting quest exposition here)~   
    IF ~~ THEN EXIT
  END

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: