Maximum value question

Say I wanted each npc to have a friendship percentage. I want the value to max out at 100 and drop over time. How would I put an upper bound on friendship such that it doesn’t overflow to something above 100. I’m pretty new to this, sorry if this is a foolish question.

3 Likes

That depends what language you are using. Is it TADS, or Inform 7, or Gruescript…? Or one of the other ones.

3 Likes

The general pattern is pretty straightforward, it’s just something like this:

friendship = friendship + newFreiendship
if friendship > 100:
    friendship = 100
3 Likes

inform7 whoops. Forgot to include that.

1 Like

If you just want to track one friendship, something like this will work. If you want more than one you should make it a property of the thing being befriended (and then the every turn rule should become a loop over the things).

"Leaping into Friendship"

Laboratory is a room.

Friendship is a number that varies. Friendship is initially 0. [ Starting value. ]

Every turn:
	If friendship > 0:
		Now friendship is friendship - 1;
	say "The current friendship is [friendship].".

To increase friendship by (N - a number):
	Now friendship is friendship + N;
	If friendship > 100:
		Now friendship is 100;

Instead of jumping:
	say "You jump into friendship!";
	Increase friendship by 30;
1 Like