Help with deciding a value.

Hello. I hope somebody can help me.

I am writing a small Halloween themed game for fun and practice, in Inform 7. I am very new at it.

What I want to achieve: A person has a scaredness value, this changes over time based on how many frights they get (scared points). Eventually this will affect how a character acts and responds (witless characters run away whereas brave ones engage).

I am following Phrases to decide other things (inform7.com/learn/man/WI_11_17.html) as my reference.

This is what I have so far:

[code]“scared wits” by Special Agent

[ http://inform7.com/learn/man/WI_11_17.html Phrases to decide other things ]

Scaredness is a kind of value. The scarednesses are brave, wary, afraid, witless.

A friend is a kind of woman.
A friend has a scaredness.
A friend has a number called scared points.

To decide which scaredness is a friend:
if the scared points of the noun is greater than 4, decide on witless;
if the scared points of the noun is greater than 3, decide on afraid;
if the scared points of the noun is greater than 2, decide on wary;
decide on brave.

To scare (frightee - a friend):
increase the scared points of the frightee by 1;
say “[the noun] gets a scare.”

Every turn:
scare Ash; [ for testing ]

Instead of examining someone who is friend:
say “[ash] is [scaredness of noun] ([scared points of the noun] scared points)”;

The Haunted House is a room. A friend called Ash is here. A friend called Jill is here.

test boo with “x ash/x ash/x ash/x ash/showme ash”.
[/code]

With this output:

Haunted House
You can see Ash and Jill here.

>test boo
(Testing.)

>[1] x ash
Ash is brave (0 scared points)
Ash gets a scare.

>[2] x ash
Ash is brave (1 scared points)
Ash gets a scare.

>[3] x ash
Ash is brave (2 scared points)
Ash gets a scare.

>[4] x ash
Ash is brave (3 scared points)
Ash gets a scare.

>[5] showme ash
Ash - friend
location: in the Haunted House
singular-named, proper-named; unlit, inedible, portable; female
list grouping key: none
printed name: "Ash"
printed plural name: "friends"
indefinite article: none
description: none
initial appearance: none
carrying capacity: 100
scared points: 4
scaredness: brave

My problem: even though Ash has scared points: 4, her scaredness is still listed as brave. It should be afraid.

Any pointers as to how I can fix this will be welcomed.

The problem seems to have to do with the use of “To decide”. When you write “To decide [which kind] is [something]”, the block is called when it needs to decide what [something] is—if [something] is already set to something, the code doesn’t need to decide it, so it’s never called.

When you write “A friend has a scaredness.”, the scaredness of all friends is initialized and set to “brave” (the first in the list). As far as I can tell, if you just get rid of that line, then whenever you call [scaredness of noun], it will have to run the code block to decide on the scaredness, which will update it properly.

I think there’s also a problem the line “To decide which scaredness is a friend:”. I think what you want is something like “To decide which scaredness is the scaredness of a friend:” instead?

That makes sense Brian, that nothing gets decided since the value is already set. Thanks!

In this case I will use another approach, and set the scaredness of the person at the time they receive the scare. This method works, but in the interest of learning I was trying out the decide method.

Here’s a modified version of the example:

"scared wits" by Special Agent

[ http://inform7.com/learn/man/WI_11_17.html Phrases to decide other things ]

Scaredness is a kind of value. The scarednesses are brave, wary, afraid, witless.

A friend is a kind of woman.
A friend has a number called scared points. [1]

To decide which scaredness is the scaredness of (F - a friend): [2]
	if the scared points of F is greater than 4, decide on witless;
	if the scared points of F is greater than 3, decide on afraid;
	if the scared points of F is greater than 2, decide on wary;
	decide on brave.

To scare (frightee - a friend):
	increase the scared points of the frightee by 1;
	say "[The frightee] gets a scare." [3]
	
Every turn:
	scare Ash;		[ for testing ]

Instead of examining someone who is friend:
	say "[The noun] is [scaredness of the noun] ([scared points of the noun] scared points)"; [4]
		
The Haunted House is a room. A friend called Ash is here. A friend called Jill is here. 

test boo with "x ash/g/g/g/g/g/showme ash/x jill".

Notes:
1 - We remove the assertion that a friend has a scaredness, since it can be computed from a friend’s scared points and we don’t want to maintain redundant info that can be inconsistent with itself.
2 - We modify this phrase to take an input parameter (F - a friend) and make our decision based on the scared points of F rather than the noun. That way, we can call this phrase and get the scaredness of an NPC even when that NPC isn’t the noun of the current action (e.g., in an every turn rule during a turn when the player is interacting with a different NPC).
3 - We change “[the noun]” to “[The frightee]” in the say statement here, since that’s who’s getting the scare. Otherwise, we could type “x jill” and be told that Jill is getting a scare that turn, when it’s really Ash who is the frightee. In other words, the noun isn’t necessarily Ash. Also, “The” should be capitalized (in case the frightee isn’t proper-named).
4 - We use “[The noun]” instead of “[ash]” here, because we might be examining Jill.

You could drop the “scaredness” type of value and use Define-adjectives instead.

Definition: a person is witless if her scared points are greater than four.

These are all great replies, thanks folks, I am learning a stack :slight_smile:

As you’re using an integer value to enumerate states, my opinion is that this is the correct place to use a new kind of value instead of a definition. I’ve called it sanity instead of scaredness though, and the order of definition is very important. We also do some pretty heavy sanity checking on the input, which results in a person not being scared anymore when they are already witless.

Note; You also had a wrong text substitution in the scare phrase; The noun is not the same as the person being scared, which is stored in frightee. If your test case was wait (z) instead of examine you would have had a fatal error, and if you examined Jill it would say Jill but affect Ash. Also, a non-distinct named person would not be capitalized.

[code]Sanity is a kind of value. The sanities are witless, afraid, wary and brave.
A person has a sanity. A person is usually brave.

To scare (frightee - a person):
If the sanity of frightee is greater than the first value of sanity:
Now the sanity of frightee is the sanity before the sanity of frightee;
Say “[The frightee] gets a scare.”;[/code]