Why can I not test a numeric variable?

Hi, I’m pulling out my hair trying to figure this out. This seems incredibly basic yet I can’t figure out what I’m doing wrong.

Early in my game I have this:

 the mugcounter is a number that varies.
 the mugcounter is 0.

Later in the game, I have this code. This code works:

 To say excomm:
 	increment the mugcounter;
 	choose row mugcounter in the Table of CoffeeMug Responses;
 		say "[phrase entry][paragraph break]";

The problem is I have 6 entries in my Table. I want the user to be stuck receiving that 6th response until they break out of that puzzle. So i thought, okay, let me test the mugcounter, if it’s > 6, let me set it to 6, which will give the player that last response over and over until they input the correct command. Perfect. So, I changed the last piece of code to the following:

 To say excomm:
 	increment the mugcounter;
 	if the mugcounter > 6:   <---- new, added code
 		now the mugcounter = 6;  <---- new, added code
 	choose row mugcounter in the Table of CoffeeMug Responses;
 		say "[phrase entry][paragraph break]";

I get the following error:

The phrase or rule definition ‘To say excomm’ is written using the ‘colon and indentation’ syntax for its 'if’s, 'repeat’s and 'while’s, where blocks of phrases grouped together are indented one tab step inward from the ‘if …:’ or similar phrase to which they belong. But the tabs here seem to be misaligned, and I can’t determine the structure. The first phrase going awry in the definition seems to be ‘say “[phrase entry][paragraph break]”’ , in case that helps.

Can I not use an IF statement within a TO SAY block? Again, I feel this is a basic thing that I’m not understanding. Sorry if this is too basic! And thanks for any help! (i did check and i’m using only tabs in the new added lines of code)

Thanks!

try “now mugcounter is 6” as opposed to the equals sign.

15.5 Arithmetic at the bottom mentions this restriction.

We can compare numbers using either the traditional computer-programming symbols, or using words:

if the score is less than 10
if the score < 10

and similarly for “greater than”, “at least” and “at most”, with the symbols “>”, “>=” and “<=”. But we are not allowed the equals sign: for that we need only use “is” -

if the score is 10

Also I’m unsure if you have to say “the mugcounter is initially 0” since it will be changing or if using “initially” is just a habit that I have.

Your last line spacing needs to be altered to match the other lines.

Logic-wise, I’d check the number before incrementing:

To say excomm:
	unless mugcounter is 6:
		increment mugcounter;
	choose row mugcounter in the Table of CoffeeMug Responses;
	say "[phrase entry][paragraph break]";

e: (although I use “unless,” using “if” phrases are fine too.)

e2: I missed the extra indent that phil was talking about

1 Like

Agree with drew. This solution allow saving the reset-to-maximum instruction, reducing the code size. (not a secondary matter, if is compiled to .z8 format…)

Best regards from Italy,
dott. Piergiorgio.

I was typing basically what Drew said when I got called away. But to go back to what Phil said and your initial error text I think there’s still an extra tab in the final line and it should be level with the choose row statement above it:

To say excomm:
	unless mugcounter is 6:
		increment mugcounter;
	choose row mugcounter in the Table of CoffeeMug Responses;
	say "[phrase entry][paragraph break]".

Also, we’re all assuming there’s nowhere else that mugcounter could be changed. If there is then that of course changes the logic a bit.

Damn. Thanks, all. I thought I had eliminated spacing as an issue. Apologies for what was, indeed, a basic issue.

There was some great answers here and lessons I’ll be taking with me as I continue to code this game.

I’m (obviously) still learning and these responses were all helpful! Thank you again!

2 Likes