Global variables?

I have a mysterious problem, but I think it stems from my not understanding what looks like a global variable.

ActiveService is a kind of value. ActiveService is none, loaning, and repaying.

then later in the code I try to print it out:

...
	if player consents:
		now ActiveService is loaning;
		say "Active service = [activeService]";

I get a parsing error?!

You wrote ‘say “Active service = [activeService]”’ but ‘activeService’ is used in a context where I’d expect to see a (single) specific example of a sayable value, not a description.

The Index shows that ActiveService is a sayable value, so why the error?
This value for ActiveServie is causing tests to fail intermittently.

The key word there is kind. You’re creating a type here, not a variable itself.

If you want to make a variable, you could then say “the current activeservice is an activeservice that varies”.

2 Likes

Nope, that didn’t work.

ActiveService is a kind of value. 
The currentService is an ActiveServices that varies. CurrentService is none, loaning, and repaying.

The parser kicks out:
The sentence ‘CurrentService is none, loaning, and repaying’ tells me that ‘currentService’, which is an activeservice that varies, should start out with the value ‘none’, but this is an object and not an activeservice.

I’m totally in the fog about this. I get the kind part, but how can an currentService as none (or anything else) be an object?

I tried to follow the docs:

Brightness is a kind of value. The brightnesses are guttering, weak, radiant and blazing.

How is this different from what I did?

When I use these statements:

ActiveService is a kind of value. The ActiveServices are none, loaning, and repaying.

I do not get a parser error. I get the error on the say statement:

say "Active service = [activeService]";
ActiveService is a kind of value.
The ActiveServices are none, loaning, and repaying.

This creates a kind of value, or what other programming languages would call a type.

The current activeservice is an ActiveService that varies.

This creates a variable of that type.

2 Likes

Because in this code you didn’t specify the possible values that ActiveService can be, I think it’s parsing “none” as referring to the nothing object.

1 Like

I did specify the values. In the code above, ActiveService is none, loaning, and repaying.

Unless I misunderstand, this should be a working variation of the code in the OP.

lab is a room.

ActiveService is a kind of value. ActiveService is none, loaning, and repaying.

CAS is an ActiveService that varies.

instead of jumping:
	now CAS is loaning;
	say "Active service = [CAS]";
	say line break;
1 Like

In the code except you cited in the post Nathaniel was replying to, you didn’t define the possible values when you set up the kind - you just said the specific instance was [list of values], but inform didn’t know what to do with that.

To zoom out a bit, the broader issue is that a kind of value isn’t a thing that exists in the world but rather a statement about the kinds of things that can exist in the world. So you need to both tell Inform “ActiveServices are this sort of thing, here’s what they can look like” - via creating the kind and its possible values - but also “here’s one particular ActiveService that I want to create, modify, and check.”

Hopefully that distinction is clear in the excerpt Drew posted above - personally I find the difference makes sense in theory but I often struggle to come up with names for the kind and specific examples that feel intuitive. So spending a little time figuring out good names at the get-go can often make it easier once you need to start using this stuff; based on the context it seems like this is basically about loans, right? So maybe “Loan status is a kind of value… indebtedness is a loan status.” Or something like that?

3 Likes

This is legitimately confusing because it’s not required when defining properties. You can say

The sword can be none, loaning, or repaying.

This is really a shortcut. You could spell it out by writing

ActiveService is a kind of value. ActiveService is none, loaning, and repaying.
The sword has an ActiveService.

For global variables, there is no shortcut; you have to write out the kind definition separately. This may be what’s tripping you up.

4 Likes

Yeah, I think that’s a great craft question! My usual thought is that names ought to be whatever feels most readable to the author. Inform is pretty flexible about naming things, so my own ideal is reaching a compromise between readability (it makes sense at a glance) and time to type.

In my own practice, I usually have longer kind names and shorter variable names.

Still, people have different reading and retention strategies, so ultimately an author should choose names that will help them read and write their own code.

1 Like

Thanks so much for this. I think I understand it better.
I now have this code:

ActiveService is a kind of value. The ActiveServices are none, loaning, and repaying.
The LoanOffice has an ActiveService.

I also see that if I say “ActiveService” only, it compiles but does not work correctly. I must say “ActiveService of LoanOffice”.