Odd variable behavior [Inform 7 release 6L02]

I’m new to writing IF and to Inform specifically, but I’m a computer programmer by trade so I expect things to work a certain way. I’m recreating Example 309 “Baritone, Bass” in my own kind of way and I ran into a behavior that I can’t explain.

When I write the code like this: (code example 1)

[code]Gender is a kind of value. The genders are masculine, feminine, and unknown. Understand “male” or “man” or “M” or “boy” as masculine. Understand “female” or “woman” or “F” or “girl” as feminine.

PlayerGender is a gender that varies.
Now PlayerGender is unknown.[/code]
I get the “Thing is a Value” error when setting PlayerGender to unknown.

But when I write it like this: (code example 2)

[code]Gender is a kind of value. The genders are masculine, feminine, and unknown. Understand “male” or “man” or “M” or “boy” as masculine. Understand “female” or “woman” or “F” or “girl” as feminine.

PlayerGender is a gender that varies. It is unknown.[/code]
It compiles and runs fine.

Later I added a line of code like this: (code example 3)

[code]Gender is a kind of value. The genders are masculine, feminine, and unknown. Understand “male” or “man” or “M” or “boy” as masculine. Understand “female” or “woman” or “F” or “girl” as feminine.

Family Relation is a kind of value. The Family Relations are parent, child, sibling, spouse.

PlayerGender is a gender that varies. It is unknown.[/code]
And then it gave me the “General description is something else” error when saying “It is unknown.”

Changing it back to this: (code example 4)

[code]Gender is a kind of value. The genders are masculine, feminine, and unknown. Understand “male” or “man” or “M” or “boy” as masculine. Understand “female” or “woman” or “F” or “girl” as feminine.

Family Relation is a kind of value. The Family Relations are parent, child, sibling, spouse.

PlayerGender is a gender that varies.
Now PlayerGender is unknown.[/code]
Still Throws the “Thing is a value” error when setting PlayerGender to unknown.

But moving the PlayerGender variable to directly after the gender definition like this: (code example 5)

[code]Gender is a kind of value. The genders are masculine, feminine, and unknown. Understand “male” or “man” or “M” or “boy” as masculine. Understand “female” or “woman” or “F” or “girl” as feminine.

PlayerGender is a gender that varies. It is unknown.

Family Relation is a kind of value. The Family Relations are parent, child, sibling, spouse.[/code]
Seems to compile and work as intended.

Why is it behaving like this? I would really expect all of these code examples to work. Is there some nuance that I’m missing? For now it seems that I can get around the issue by being careful about where I declare my variables, but I’d really prefer to declare them all together for readability’s sake.

In several of your examples “Now” is causing you a problem. “Now” can only be used for changing things in the course of play; it has to be in a rule or phrase, not in a bare assertion. I guess in programming terms, “now” has to be for something that gets executed in runtime, not the initialization of a variable at startup? I may not have those terms right. Anyway, you can’t just write “Now PlayerGender is unknown” because Inform is asking itself “When is that supposed to happen, exactly?”

(The specific error message is not that helpful here; what’s going on is that Inform thinks you’re trying to create a thing called “now playergender” and set it equal to “unknown,” which can’t happen because a thing can’t be a value.)

Anyway, you don’t want “now” in the code there. Look at §8.11 of Writing with Inform – this explains the difference between “S.” and “Now S.”

For Code example 3, the problem is that Inform isn’t understanding what “It” means. Change it to “PlayerGender is unknown” and you should be OK.

In fact, though code example 2 is compiling, I don’t think it’s actually setting PlayerGender to unknown. (I tried “every turn: showme playergender” and it’s coming back masculine, which is the default value because it was listed first.) Exactly how “it” gets processed may be a secret that is buried in the inner workings of the compiler, but I think it’s usually used for strings of definitions pertaining to things, not variables: “The box is a container in the Orrery. It is closed. It is openable. It is locked.” When in doubt, write “it” out – hey, that rhymes!

PlayerGender is a gender that varies. PlayerGender is unknown.

As matt says, this is the correct way to write this out. However, Inform now supports a shorter form:

PlayerGender is initially unknown.

“Initially” implies that this is a value that varies, and Inform can deduce the type because “unknown” is a gender.

If you’re used to C++, the “initially” syntax is somewhat like the new “auto” type in C++11.

Thanks for the responses. Getting rid of the Now keyword fixed my issue. I guess that really makes sense when you think about it.

It’s kinda hard to find on the Inform website, but I wrote a manual specifically for programmers coming to Inform. The “whirlwind tour” chapter might be all you need.
Link in sig.