Struggling with Referencing Table Entries

I’m trying to make a table consult-response system so that a character will respond with a table entry to every question, but only one specific question will trigger a change in the character’s behavior that will cause it to no longer answer questions. I’ve consulted both the Documentation and Jim Aiken’s Inform 7 Handbook and in both I cannot find what I am exactly looking for.
Here is the code I have so far:

Instead of consulting the Librarian about something:
	if the topic understood is a topic listed in the liblexicon and the librarian is uncursed:					
	           if the topic understood is "volume" and the liblexicon is Table of Library: 
		         say "Cursed"; [just testing for author reference]
		         now the librarian is cursed;
		       do nothing;
	say "[knowledge entry][paragraph break]";
	otherwise if the librarian is cursed:
		say "I can't tell you about that";
                say "I can't tell you about that".

Right now, it’s triggering the “if the topic understood is volume” even if that topic is not the one being asked, and I’m having trouble understanding how to use nested conditionals in this way. Thanks!

1 Like

Can you put your code in a code block so we can see the indentations? Like this:

<code goes here>

1 Like

Welcome to the forum! Per Phil’s post, for issues around nesting it’s hard to troubleshoot without seeing the actual indentations, which is what the code block tool is far. If it’s easier than typing the back ticks, there’s also a button that does it automatically - just click the little button in the post header that looks like </> and paste in your code!

I’m on my phone right now so not able to mess around with the code, but there are a couple things that might be going wrong:

  • I believe that “otherwise” phrases have to come right after an “if” clause to work properly, but here it looks like there’s an always-firing “say” command that interrupts the chain (also, should that always be firing? I’d think it shouldn’t if the librarian is cursed, for example).

  • That last “otherwise” looks nested under “otherwise if the Librarian is cursed” when it looks like it should get only one tab.

Again, apologies for not being able to type up and test anything more robust right now! If it’s helpful, you might want to try two things to clean up the code a bit and see whether they fix things:

  • Reorder the code so the conditions that interrupt the regular action come first - I’d start with the “if the librarian is cursed” condition, then “otherwise if the topic is not listed” (which right now is handled by the final, possibly-not-working “otherwise” catch all), then do the situations where the player is actually asking an uncursed librarian about the proper topic.

  • If the logic of the otherwises is getting snarled, you can just use a regular if statement and append an “instead” to the subsequent command to wrap up the action without stepping through the rest of the logic (so under “if the librarian is cursed” you’d write a tab and then “say “I can’t tell you about that.” instead.”) The nice thing about doing things that way is each “if” statement will be more self-contained so it’s easier to debug.

Hope this is at least a bit helpful!