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:
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
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.)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:
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.)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:
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:
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:
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.