The game of Operation with high stakes

At one point in my story, the player is confronted with the game Operation and has to determine which pieces to remove. I’ve looked at this coding a hundred times but can’t figure out why it won’t run. Thank you in advance from the community. The code below kicks out an error on the very first line and I have used the instead of taking rule many times successfully. For some reason when displaying the text on this post it does not show the indentation. But the code in the game is indented and I don’t think it’s the problem

instead of taking liver:
	if rownumber1 is not 1:
		say "You feel this strange feeling inside, as if someone or something is interfering with how your body is functioning.  A moment later you are doubled-over in pain and collapse.  Unfortunately[paragraph break] ***You have died***" instead;
		end the story finally;
	end if;
	otherwise:
		say "You feel better!  Somehow what you did made a difference in your health.  The tiny plastic liver piece disappears from your hand.";
		now liver is nowhere;
		increase score by 1;
		if aentry is "liver":
			now diag1 is "[blank]";
		end if;
		else if centry is "liver":
			now diag2 is "[blank]";
		end if;
		else if if eentry is "liver":
			now diag3 is "[blank]";
		end if.

If you put three backticks (```) before and after your code, it’ll keep the indentation. I added it to your post for now.

2 Likes

Thank you!

1 Like

Ah, you fixed the formatting while I was writing a note telling you how to.

Okay, the first problem I see is that the line ‘You feel this strange feeling…’ etc. ends with “instead”. That means, that line will run, and then no more code that comes after it will run. In other words, it never gets to the next line, ‘end the story finally’.

What’s probably happening is the game is resuming somewhere unintended after the attempt to take the liver.

Could you explain what error you’re getting exactly? A candidate I could guess at is that you’ve created a loop where the failure to take the liver tries taking it again, creating an endless loop which crashes the game straight away. But we need some more info first.

-Wade

1 Like

I actually added the instead after the error. I removed it again and get the same error:

Problem. The rule or phrase definition ‘instead of taking liver’ 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.

1 Like

Ah okay, it’s something to do with your code formatting. I’m not sure I can help you with the specifics myself, as I don’t use 'else’s and I don’t use 'end if’s. These are just personal preferences in how we format the code. For instance if I wrote this, it would look like:

instead of taking liver:
	if rownumber1 is not 1:
		say "You feel this strange feeling inside, as if someone or something is interfering with how your body is functioning.  A moment later you are doubled-over in pain and collapse.  Unfortunately[paragraph break] ***You have died***";
		end the story finally;
	otherwise:
		say "You feel better!  Somehow what you did made a difference in your health.  The tiny plastic liver piece disappears from your hand.";
		now liver is nowhere;
		increase score by 1;
		if aentry is "liver":
			now diag1 is "[blank]";
		otherwise if centry is "liver":
			now diag2 is "[blank]";
		otherwise if eentry is "liver":
			now diag3 is "[blank]";

I would expect that to work, but you probably want to maintain your style. Someone who knows the different formattings, or does them more your way, will probably come along to help in this topic if you can’t work out which bit you need to cut or indent or whatever…

EDIT - I just noticed you’ve got a double ‘if’ in the line ‘if if eentry’, too. Try cutting that.

-Wade

2 Likes

To hell with maintaining my style, I just want something that WORKS and your text did. Thank you!

3 Likes

For reference, though, the problem with your original code was the "end if"s, which aren’t needed (or permitted) in the colon & indentation format. Remove them,and it’s fine (except for the repeated “if” in the 3rd line from the bottom).

4 Likes

Thank you!