To understand my displeasure is to understand some basic scripting logic: throughout a typical NPC quest script, comparisons are made:
if a player has the quest item
{
then say some things
and take the quest item
and give a reward
}
otherwise
{
tell the player that they do not possess the quest item
}
end
The problem with this format is that it's too (ahem) positive. The script begins by making a comparison for a true condition, and if the comparison is true, then I do some positive stuff – otherwise the comparison is false, and I do the negative stuff. This style becomes harder to read when there are multiple positive comparisons:
if the player is alive
{
if the player has the quest item
{
if the player's gender is male
{
then say "Attaboy!"
}
otherwise the player's gender is female
{
then say "Attagal!"
}
then take the quest item
give the reward
}
otherwise the player does not have the quest item
{
tell the player that they do not possess the quest item
}
}
otherwise the player is dead
{
look sympathetically at the player
}
end
While there's nothing wrong with the logic of this code (at least I hope so; I have not debugged it!), I find it rather difficult to read. What I should have done is to design the script to make negative comparisons, and if the negative comparison is true, then do not make subsequent comparisons:
if the player is not alive
{
look sympathetically at the player
end
}
if the player does not have the quest item
{
tell the player that they do not possess the quest item
end
}
if the player is not a female
{
then say "Attaboy!"
}
otherwise
{
say "Attagal!"
}
take the quest item
give the reward
end
The rewrite is easier to read in that it filters out any of the negative possibilities first; by first eliminating any "negative" conditions, then whatever conditions remains must be "positive". If the player is not alive, then it does not matter if the player has the quest item: stop here and check no further. If the player does not have the quest item, then the player's gender does not matter: stop here and check no further.
Who would have thought that negative thinking would have been so positive?
No comments:
Post a Comment