Login
Remember
IF Answers
Ask a Question

# Inform: How do I find the word count for text the player can read?

+3 votes
219 views
asked Jun 1 in Authoring by dacharya64 (18 points)

Hi all!

Is there a way in Inform to calculate the word count of a piece, but just the words that the player can see? (that is, prose, not code).

Any help would be appreciated!

Thanks,
Devi

- inform7
- word-count

## 2 Answers

+3 votes
answered Jun 3 by Joseph Geipel (207 points)
selected Jun 4 by dacharya64
Best answer

Obtaining the word count of all the possible text that the player can see is not really generally possible, using Inform 7 code or not, for reasons well explained by Michael Hilborn in this blog post:

> "Unfortunately, word counts in IF are relatively meaningless, especially since the process of defining what is meant by ‘word count’ in IF is nebulous at best. When Inform 7, an IF-authoring tool, explains that it has generated a story of 20,000 words, it refers not only to the prose presented the player, but also to the game’s code—a glorious amount of text that is generally never experienced by anyone but the author. If we are to ignore code in the word count, which is often suggested, then perhaps we can only count the words encountered by the player. Even this is problematic, for a majority of this prose may consist of standard responses, not author-generated content; or, perhaps, the author has written only a few lines of text, but through the trickery of randomness and some clever use of code, the game erupts with an infinite supply of unique prose."

Nevertheless, some approximations are possible, but these are for your own purposes and aren't calculated by the game code proper. The two I could think of are:

1. Finding out how many words in your code is within quotation marks within the Inform 7 IDE, with help from outside (say, some regular expression tricks). This will include "[one of]" and if statements within text, and it will return only 4 words in the case of "[list of visited rooms]". The Inform 7 IDE does not have the ability to calculate this itself unlike the general word count.

2. Finding the word count after the end of a specific session. This is easy with transcript copy-pasting into a word processor that has word count, although you may need to make a few adjustments.

All in all, though, the answer to whether Inform 7 has a good way to calculate the prose word count is that it doesn't due to the inherent complexities and exceptions that arise.

commented Jun 4 by dacharya64 (18 points)
Great--thanks so much for your answer!
0 votes
answered Jun 19 by AndrewS (250 points)

I've used some regular expression tricks to find word counts. So I'd like to share here if anyone is interested.

    open(A, "story.ni");
    open(B, ">story.txt");
    while ($a = <A>)
    {
      if ($a !~ /\".*\"/) { next; } #skip any line without two quotes
      $a =~ s/^[^\"*]\"//g; #eliminate all before quote #1
      $a =~ s/\"[^\"*]$//g; #eliminate all after quote #2
      $a =~ s/\[[^\]]*\]/ /g; #convert stuff between brackets to a space. As mentioned above, there're problems with stuff like [if player is female]s[end if]he becoming 2 words here instead of 1, but on the other hand, [one of]Yay[or]Woo[or]Neat[stopping] should be 3 words. Just an example of how simple cases make it tough to be exact. I suppose we could give a maximum and minimum bound for words (spaces or no spaces) but being exact is tricky.
      print B $a;
    }
    close(A);
    close(B);

I think it would be neat to have this, or preferably something more refined, in tools somewhere because I think a lot of people have this question.

Hopefully this can help people out with regular expressions too. If they're curious.

commented Jun 19 by Juhana (246 points)
You might want to add some instructions on how to use that script, or at least which programming language it's written in.

## Related questions

- Inform: How do I get the player to input a name for themselves? The name keeps changing to whatever the player typed last!
- The inform IDE is only so flexible for text editing. Do I have to use it?
- How to get rid of a rule that's blocking what I want the player to do? (Inform 7)
- How do I change 'if the player consents'? pre-Inform 6L or post-
- How do I find the default parser verbs in Inform?

...