Multiples of the same kind of thing with different effects

So I’m a newbie to Inform 7 and am finding myself oddly fixated on trying to make something happen. This forum has been wildly helpful so far in overcoming most of my stumbling blocks. I’m a web developer for a living so I’m used to coding, but I think I’m being thrown off by this almost-natural-language-that-doesn’t-look-structured-but-actually-is…

Anyway, I am trying to make a box of raisins in which every raisin has a different effect on the player’s mood. I’ve defined a value “effect” that can be happy, neutral, or sad. I want them all to be sad to start with, and a few of them be happy. (I did try calling the effects “positive” and “negative” but those seem to be reserved words, so… happy and sad it is!)

A raisin is a kind of thing. A raisin is always edible. A raisin has an effect. A raisin is sad.
A box of raisins is in Kitchen.
A box of raisins is a container. 
A raisin called first raisin is in a box of raisins. First raisin is sad. The description of first raisin is "It looks very raisin-ish."
A raisin called second raisin is in a box of raisins. Second raisin is happy. The description of second raisin is "It seems like a raisin."
A raisin called third raisin is in a box of raisins. The description of third raisin is "Confirmed: raisin."
A raisin called fourth raisin is in a box of raisins. The description of fourth raisin is "Yeah. It's a raisin."
A raisin called fifth raisin is in a box of raisins. The description of fifth raisin is "What were you expecting?"

Now, here is what I’m trying to do - I want it to check any raisin and increase or decrease the mood accordingly. But I can’t seem to get the phrasing on the IF statement:

After eating a raisin:
	say "testing - [effect]";
	if effect of a raisin is happy:
		increase the mood of the player by 1;
		say "Tastes like raisin. Not bad. Your mood is [mood of the player].";
	otherwise:
		decrease the mood of the player by 1;
		say "This raisin tastes like despair. Your mood is [mood of the player].".

This failed because “a raisin” isn’t specific enough. But if I try “the raisin”, it seems to be trying to read “effect of the raisin is happy” as a single statement. It’ll work if I actually specify “first raisin”, “second raisin”, etc. But surely I don’t have to repeat this whole thing for every raisin in the box?! There must be a way to actually refer to “the current raisin that is being acted on”… no?

Thanks very much!

Is it necessary to decide the effect of the raisin before it’s eaten?

A raisin is a kind of thing. A raisin is edible. 
The description of a raisin is "[one of]It looks very raisin-ish.[or]It seems like a raisin.[or]Confirmed: raisin.[or]Yeah, it's a raisin.[or]It's a raisin. What were you expecting?[then at random]"

Kitchen is a room.
a red box is an openable, closed container in Kitchen.  red box contains five raisins.

After eating a raisin:
     if a random chance of 1 in 3 succeeds:
          increase the mood of the player by 1;
          say "Tastes like a delicious raisin. Your mood is [mood of the player].";
     otherwise:
          if a random chance of 1 in 2 succeeds:
               decrease the mood of the player by 1;
               say "This raisin tastes like despair. Your mood is [mood of the player].";
          otherwise:
               say "This is a perfectly normal raisin. It does nothing to your mood.";
          end if;
     end if.

2 Likes

I would do things the way Hanon outlines, but as to your original question, the phrasing you’re looking for is:

After eating a raisin (called the foo):

And then in the text of your rule you’d just add conditions like “if the effect of the foo is happy” and so on. The “foo” label is what allows you to tell Inform that you mean the specific raisin that was being eaten to kick off the action.

1 Like

Thanks - this makes sense to me, but doesn’t translate… I get “Problem. The rule or phrase definition ‘After eating a raisin’ seems to use both ways of grouping phrases together into ‘if’, ‘repeat’ and ‘while’ blocks at once. Inform allows two alternative forms, but they cannot be mixed in the same definition.”

I don’t see any repeat or while in there, so I’m not sure what I’m missing - I’m looking over the syntax and it looks like what I would expect to be right… but as mentioned, I am new at this.

Ahhhh - that does wonderful things! And seems like an important thing for me to have learned. Thank you!

1 Like

I’m not in front of my computer now so I can’t confirm, but I think the issue is just that with the indenting you don’t also use the “end if” line to end your conditionals - if you delete those lines I think the code should work.

That did indeed work - the formatting changed in the copy-and-pasting and I just had to replace spaces with tabs and then it was fine. Awesome, now I have two different strategies to play with - thanks so much!

2 Likes

Did I do that wrong? It’s been a while since I had Inform open and I might be confusing needing “end if”. My bad!

Yeah, if you do the nested tabs you don’t need “end if”s - I think it’s generally fine to use them, but the error the OP was getting made it sound like Inform was somehow getting confused between the two methods? Anyway sounds like it was just a copy and paste issue and your code I’m pretty sure should work as written - I also didn’t (and don’t) have the IDE open to test things so I’m just spouting off :slight_smile:

1 Like

I think I’m confusing with needing them inline, as in

say "The door is [if red door is open]open[otherwise]closed[end if]."

2 Likes