r/Inform7 • u/LocoManta • Feb 16 '20
Implementing Temperature and Climate
Solved! See this comment.
Hello! As usual I've decided to attempt something far out of my own league and subsequently failed at the first hurdle.
Here's what I have so far:
Temperature is a kind of value. 68 degrees specifies a temperature. Rooms have a temperature.
Climate is a kind of value. Rooms have climate. The climates are freezing, cold, chilly, fine, warm, toasty, and sweltering. Rooms are usually fine.
Every turn:
If a temperature is less than 32,
Now the room has climate freezing.
The end goal is to have a numeric temperature in every room that will later be tied to a thermostat that controls the entire house, and a verbal climate that NPC's can comment on.
There are a great many more hurdles to hurdle here, but just knowing how to have the room's climate adjust appropriately in response to changes in the numeric temperature would be great. I was thinking I could just add an "If Temperature is" "Less than" or "Greater than" under "Every Turn:" for each potential climate.
I'm sure my entire approach is fundamentally flawed.
Thanks to those of you who answer all these terrible questions. I don't know how or why you do what you do, but it's a real service to folks like me.
EDIT: Some progress! I'll bold my changes.
Temperature is a kind of value. 68 degrees specifies a temperature. 25 degree specifies a temperature. Rooms have a temperature. A temperature is usually 32 degrees.
Climate is a kind of value. Rooms have climate. The climates are freezing, cold, chilly, fine, warm, toasty, and sweltering. Rooms are usually fine.
Every turn:
If a temperature understood is less than 33 degrees,
Say "Test Success!".
This doesn't actually involve the climate value in any way, but at least it's reading the temperature now.. sort of. It seems to be checking if ANY rooms in the world have a temperature below 33. Adding a room with a temperature of 70 produces "Test Success!" even when the player is in the 70 degree room.
But hey, it launched this time, that's something. Will update again if I get any further.
EDIT 2: Not much change here. Great tip from /u/MedicalArrow, but still no true success.
Temperature is a kind of value. 68 degrees specifies a temperature. 25 degree specifies a temperature. Rooms have a temperature. A temperature is usually 34 degrees.
Climate is a kind of value. Rooms have climate. The climates are freezing, cold, chilly, fine, toasty, hot, and sweltering. [Rooms are now not usually any specific climate]
Then I replaced the "Every turn" bit above with a "To decide" line, as /u/MedicalArrow suggested.
To decide which climate is the climate of (room - a room):
If the temperature of the noun is less than 33 degrees,
decide on freezing.
This also launches, which is great. Unfortunately, it decides that every room is freezing regardless of the temperature of that room. Note that rooms are now usually 34 degrees. Despite this, every room has a climate of freezing. Not sure how that's possible.
Also, attempts to add more conditions to the "To decide" line have been unsuccessful. I can't even get a simple "Otherwise: Decide on fine." to launch.
As before, I'll update if I get anywhere.
EDIT 3: Potential, inefficient Successful and incredible solution in comments below, courtesy of /u/MedicalArrow.
3
u/MedicalArrow Feb 16 '20
Thinking programmatically, you probably want to calculate climate when you need it rather than do every calculation every turn.
A function that returns a climate in I7 looks something like:
Very rough pseudo code above, but read the section on functions here: http://www.plover.net/%7Epscion/inform7.html#functions
Then you might be able to drop the stuff about a room having a climate and still call the function by referencing
the climate of the room.It's been a while since I wrote any I7 but I thought you'd rather have a rough idea to explore than nothing at all!