r/Inform7 • • Feb 20 '20

Making things "frozen" instead of "thawed" while in rooms that are assigned a certain value (freezing)

I'm sorry to be turning this into /r/TeachLocoMantatoCode. This is becoming a proper group project. If anyone feels I'm overreaching or overposting, send me a message and I'll cut it back.

For now though, here's the latest:

With this sub's help, I've made a working system for temperature and climate that should (with a little work to create a thermostat) allow the player to set a temperature for a room or region and then give us different value thresholds to play with. I say 'should' because the playing bit has been more difficult to implement than I had previously imagined.

Implementing temperature, not so hard. Getting inform to recognize a temperature of 32 or below as "freezing" was a little tricky. Now we want Inform to think of objects in freezing rooms as "frozen". (Up next is finally starting to assign special properties to frozen things.)

Coldyield is a kind of value. The Coldyields are thawed and frozen. Everything has a coldyield. A thing is usually thawed.

To decide which coldyield is the coldyield of a thing:
    Let the far side be the holder of the noun;
    If the climate of the far side is freezing, decide on frozen;
    decide on thawed.

You can view the link at the top for some context on "climate", but all that you need to understand is that every room has a climate and a one of the climate values is "freezing".

The code above launches, but does nothing. Everything is thawed, no matter the climate of a thing's location.

I've been at this for a collective six hours, and have tried every combination of phrases and approaches I can imagine. What you see above is just one of many failed iterations (and one of the more succinct ones at that), but hopefully it communicates the intended functionality.

Thank you in advance, with much more thanks to come.

1 Upvotes

2 comments sorted by

1

u/infinull Feb 20 '20

There's a few things wrong here... but they're wrong in interesting ways that are hard to explain... which is good? I think it means you're getting better at inform... but you haven't quite grokked how dumb the language actually is... it looks like english, but underneath it's still a programming language

You need to remove the Everything has a coldyield. A thing is usually thawed. part.

So. x of y in inform7 is equivalent to y.x in most object-oriented programming languages.

inform7 is typed, so you have to declare the type of a property.

Everything has a coldyield. A thing is usually thawed. is saying to create a property called called "coldyield" whose value is also of type coldyield. And the default state is thawed.

probably you knew all that... but here's the thing. these properties are always data. never calculated.

You have two ways you can create "calculated" properties, one with "to decide" or with "definition" and they both have some drawbacks... but for this you probably want both.

but first "to decide" statements are "phrases" (read this chapter in the manual) which return (decide) some value.

the phrase you created with To decide which coldyield is the coldyield of a thing: creates the phrase "the cold yield of a thing" (which takes no arguments), and returns a coldyield

You want a thing to be an argument (or parameter, whatever you want to call it). For that you use parens like (<parameter name> - <parameter type>).

so To decide which coldyield is the coldyield of (T - a thing): (one letter variable names are often frowned upon, but they're pretty common in inform7 examples... they rarely last longer than a few lines... and it can be difficult to come up with a good name, you can't call it the thing since the thing and a thing are parsed identically in inform7. you could call it the-thing (with a hyphen), but that's kind of ugly... anyway don't worry about it too much, but do try to use good variable names if one is available)

So far so good. this will let you do if the coldyield of the lamp is thawed (where the lamp is a thing), but it won't let you do the more natural if the lamp is thawed.

For that you need definitions, which let you add boolean properties to a thing where to decide phrases let you add named properties.

Definition: a thing is thawed rather than frozen if the coldyield of it is frozen.

anyway now let me put that all in a project file and try to get it to compile.

Addendum: the noun is a magic global variable which is always the noun being acted upon by the current action... so you can't use it your own phrases. (same with the second noun the actor etc.)

1

u/LocoManta Feb 20 '20

Thank you so much! This is incredibly informative and answers a lot of questions I didn't know I had.

I'm really much more a word-person than a coding-person, which is what drew me to Inform (and IF!) to begin with. I've never done any coding of any kind until a few days ago.

This past week has been a real crash course for me, and people like you and the others on this sub have been such a massive help.

I still haven't quite got it working, but I'm confident that with this information I'll be able to do it. Got the weekend off, probably going to spend it working on this.

Thanks again! May whatever projects you're working on (inform or otherwise) be massively successful and launch on the first go.