How can I non-hardcode this?

pastebin.com/3iUzXe1V

I’m wanting to make it automatically display “is experiencing an incompatibility issue” if the corresponding row in the Table of Robot Microcodes is blank. How can I do this better? And is there any way to directly check the row equal to the programming of the robot instead of having to do that hardcoded lookup?

I’m basically wanting to make a game with various AI that can be swapped between the different IF characters, allowing you to solve puzzles through creative usage of the AI. E.G. using a “pizza baker” AI to make a robot throw something up so it will hit a sprinkler and set it off, or such. This is my framework so far.

Here’s what I came up with.

Table 1.1 - Table of Robot Tables
Code	Table (table name)
"Mayor Code"	Table 1.2
"Nacho Code"	Table 1.3
"Broken Code"	Table 1.4

Table 1.2	- Table of Robot Mayor Microcode
Robot	Code
PUP	"waving mayorally"
CAT	"twitching its whiskers bossily"
RED	--

Table 1.3 - Table of Robot Nacho Microcode
Robot	Code
PUP	"emitting nacho smells"
CAT	"meowing the word 'NACHO'"
RED	--

Table 1.4 - Table of Robot Broken Microcode
Robot	Code
PUP	"sparking"
CAT	"sparking felinely"
RED	"functioning aggressively"

After looking:
	if the number of visible blank robots is greater than one:
		say "The following robots are idling: [list of visible blank robots].";
	otherwise if the number of visible blank robots is one:
		say "[List of visible blank robots] is idling.";
	repeat with robot running through visible robots:	
		if the robot is not blank:
			say "[The robot] is ";
			if the programming of the robot is a code listed in Table 1.1 and the robot is a robot listed in table entry and there is a code entry:
				say "[code entry].";
			otherwise:
				say "experiencing an incompatibility issue.";		

If you prefer, you could also dispatch first on the robot and then on the programming, in which case you’d have a subtable for each robot instead of a subtable for each code type.

Edit: incorporate matt w’s suggestion of using robots directly in the tables instead of their printed names.
Edit: multiple code simplifications.

And is there any way to directly check the row equal to the programming of the robot instead of having to do that hardcoded lookup?

Do you mean column? Are you referring to this part?

I'm wanting to make it automatically display "is experiencing an incompatibility issue" if the corresponding row in the Table of Robot Microcodes is blank. 

For this, you should be able to use “if there is (a table entry):” from Writing with Inform §16.7. So once you have chosen a row and you know you want to look at the mayor code entry, say something like:

if there is a mayor code entry: say the mayor code entry; otherwise: say "is experiencing an incompatibility issue"

if the programming of the robot matches the text "Mayor Code": say "[the mayor code entry][no line break]"; if the programming of the robot matches the text "Nacho Code": say "[the nacho code entry][no line break]"; if the programming of the robot matches the text "Broken Code": say "[the broken code entry][no line break]"; say ".".

By the way, you should be able to make the values in your first column robots instead of text strings–I don’t think you’re gaining anything by filling the first column with texts and then checking to see if they match the printed name of the robot.

I think there may be an answer to the question I think you’re asking, but it might involve some Inform 6 phrasing. (Checking rows is easier–that’s just standard looking up rows. But if that’s what you mean, I’m not sure what part of the code you’re referring to.)

Also, it’s OK to post code of the length you put in pastebin to the forum, under a spoiler tag. Even more convenient is to boil down the example to a short bit of code that focuses entirely on the question you’re asking.

Thank you both a lot! I meant the column, yes. I had it pastebinned as I was posting it on another board seeing its opinion as well, though I believe this is the best solution. I had forgotten I could directly index the robots as themselves rather than printed names, oops. I will be using the multiple table solution you have posted. However, it does not seem able to resolve one line in this code; where would I add a corresponding choose row?:

“You wrote ‘if the programming of the robot is a code listed in Table 1.1 and the robot is a robot listed in table entry and there is a code entry begin’ : but no row seems to have been chosen at this point, so it doesn’t make sense to talk about the entries within it.”

When you say “if the X is a Y listed in Z”, then, if the condition is true, that row is automatically chosen, so you don’t need an explicit “choose row” statement. You just have to be careful not to try to access the entries if the condition is false. Since evaluation of “and” short circuits, this ought not to be a problem here. See §16.12.

The code that I posted works for me under version 6M62. I see a “begin” in what you’ve quoted that wasn’t in the code that I posted. If you’ve made changes, maybe post the whole after looking rule and we can take a look at it.

Here’s a more verbose version of loop with explicit choose statements:

	repeat with robot running through visible robots:	
		if the robot is not blank:
			if the programming of the robot is a code listed in Table 1.1:
				choose row with a code of the programming of the robot in Table 1.1;
				let code table be table entry;
				if the robot is a robot listed in code table:
					choose row with a robot of robot in code table;
					if there is a code entry:
						say "[code entry].";
						next;
			say "experiencing an incompatibility issue."

Apparently it was because I was using an old Inform version! I did not know that Inform had an update since 6L; it works fine now. Thank you!