Making a number depend on general algebra of other numbers?

Hi all,

I am experimenting with Inform 7, and seeing about creating RPG-type game mechanics.

I am trying to create a situation where you can become friends with an NPC, and their opinon of you is dependant on your reputation and on your personal history with them.

So, i have defined three numbers:

…and I want to set it up so that “NPC’s familiarity = player’s reputation + NPC’s howmuchtheylikeyou”. The game mechanic that i have in mind involves using all three numbers separately depending on the situation, thus it would be useful to define “reputation” and “howmuchtheylikeyou” separately, and then use a combined value (“familiarity”) in some situations. I could just add them together when i need them, without bothering to have a combined value called “familiarity”, but i think that would just lead to the exact same problem later on - i mean, compare “if familiarity of the noun > 20” to “if reputation of the player plus howmuchtheylikeyou of the noun > 20” - the latter option seems much more prone to ambiguity (and frustration) further down the track, especially since Inform doesn’t seem to use brackets in the way mathematicians use them (inform only seems to allow statements like “a + b > 20”, not “(a+ b) > 20”, if you get my drift). For the sake of argument, i’d like to know how to define a third value that encapsulates that concept from the beginning, without needing to think about it further down the track. I’d like to know how to solve this problem, and if it’s unsolvable, i’d like to know that as well, if only for the sake of working out how Inform reads things.

I started with:

… which returns the error:

Another try:

returns…

…and…

gives me…

I could go on and on like this! I’ve tried about a dozen more different ways of attempting to add two number together to create the third number, but unfortunately i only discovered this forum a few minutes ago, so i haven’t saved all the different formulations i’ve tried.

Consistent problems seem to be that Inform doesn’t actually recognise the bracketed “(NPC - a person)” in this context, or that it doesn’t realise that “reputation” and “howmuchtheylikeyou” are actually supposed to be numbers, and thus can be added together (even though that’s explicitly defined, it often seems to treat them as values that contain text).

I’m pretty sure there’s some fundamental kind of syntax that i am not understanding, that mathematical words like “plus” and “minus”, and things like “(NPC - a person)” actually only have meaning to Inform under certain specific conditions, and can’t simply be used wherever you want. But i can’t figure out what those conditions are, and it’s really not clear to me at all in the manual.

So, how do you add together numbers that belong to people (whether player or NPC) in the gameworld? How do you make Inform understand a general statement like “a = b + c” - where b and c could have different numerical values depending on which characters are involved?

How do you do algebra in Inform?

I think this should work (I haven’t tested it, though):

To decide on the familiarity of (NPC - a person): decide on reputation of NPC + howmuchtheylikeyou of NPC.

If it doesn’t, then something like the following should work:

Every turn: repeat with NPC running through people: let familiarity of NPC be reputation of NPC + howmuchtheylikeyou of NPC.

Thank-you for the very swift reply :slight_smile:

The first idea you suggested turns up this:

…the impression i’m getting from the error message is similar to the impression i had with earlier error messages, the program seems to not be treating the various numbers as numbers. Is that a reasonable reading of the errors?

I am tinkering with the second one now; it still produces error messages, but i altered the punctuation a bit and came up with a new error message that i haven’t seen before:

I haven’t seen this one yet! It looks like something that ought to be in the manual sonewhere.

I always tried it while omitting the “plus the howmuchtheylikeyou of the NPC” bit, so it’s just “let one number be another number” - same error message. Then i tried it with “let familiarity of NPC be familiarity of NPC plus 1”, which is a sort of phrase that i know i’ve seen Inform7 accept before, and it produced the same error message again.

Based on your ideas, i came up with this:

…and it works!

I have a command that lets you view the numbers associated with different characters, so i could track whether it was working or not.

It doesn’t do anything at the start of play (since it’s an “every turn” rule), but after the first move, all of the “familiarity” numbers suddenly come out correctly.

I tried it in a room with three NPCs, and gave each one a distinct “howmuchtheylikeyou” value (1, 3, and 5), and then gave the player a “reputation” value of 5, and each “familiarity” value came out exactly as it should have for each character (6, 8, and 10!).

So now i can create character statistics that interact with the statistics of the player… i imagine you could almost create a “Warhammer”-style RPG this way (since the game mechanic of Warhammer involves character statistics that interact with each other, and are thus different for each pair of characters)…!

Thank-you again rioshin for your suggestions that led to the answer!

This works (and is the best, simplest way to solve this problem):

To decide what number is the familiarity of (NPC - a person): decide on reputation of NPC + howmuchtheylikeyou of NPC.

Section 11.17 of the manual explains how this works.

Just a warning: if you use the every turn rule to update the value, it will not be updated until the end of the turn. Consider this:

[At the beginning of the turn, howmuchtheylikeyou of Bob is 6 and reputation 2, so familiarity is 8]

After attacking Bob:
   decrease the howmuchtheylikeyou of Bob by 10;
  [Note: howmuchtheylikeyou is now -4 and reputation 2 but familiarity is still 8]
   if the familiarity of Bob is less than 0:
      say "'I'm not surprised, considering it's you,' Bob says.";
   otherwise:
      say "'Why would you hit me? I thought you were the good guy,' Bob cries." [this option will be selected.]

[at the end of the turn, familiarity is updated to -2.]

So with an every turn rule familiarity always represents the situation at the end of the previous turn, not the current situation. Which might or might not be what you want. ‘To decide’ solution always gives the up-to-date number.