Table of Flags...

Alright, so I toyed around with doing this as a truth state (boolean) check, which got me nowhere. Possibly because I don’t know a friggin’ thing about this mechanic. I obviously don’t know a friggin’ thing about table mechanics, either. I’ve been rapid fire searching games on IFDB with IF7 source code for references to tables and am either too impatient, near sighted or just plain ignorant to pick any out.

Basically, as the title indicates, I want a table of flags. Inform is having none of that. I’m not finding anything in the tables section of the documentation deal with if statements and table values. Nor am I finding anything workable in the “Inform Handbook”, which assures me that I’m basically failing at this.

Take the following code, for example. I want to see if the water is on. So, I do this:

[code]Table of Flags
event flag
“wateron” 0

Choose the row with an event of wateron in the Table of Flags.
If the flag entry is 0:
Do this.[/code]

Now, I’ll go ahead and say that this example is in a scene and happens instead of turning on the water. I’m not sure how much additional information I should provide, as I’m rather embarassed with my code at this point and it really seems as though this snippet is the root of this particular evil. Pride is an ugly thing and I’m brimming with it.

Anyway, Inform comes back with this error:

And no, that’s not what I’m saying at all. I’m not sure, Inform, why you would believe that.

I’ve been following along with examples in Mr. Aikin’s book, but not exact examples, as his conditionals regarding table values are part of rule creation, which I don’t think I’m trying to do. Though I might be…

In this particular example, I want to check whether the water is on or off. If it’s on, tell the player it’s on. If it’s off, let the player turn it on. But Inform is having none of that.

I also tried some wordy example from the documentation about some value coinciding with something or other… Not only did that look completely wrong as soon as I started typing it, I couldn’t even syntactically figure out how to make something that resembled a command out of it.

So… Ideas, questions or admonishments are welcome. Doesn’t seem like this is a difficult or uncommon thing to do, so I’m sure I’m just doing it wrong.

I don’t know how direct a quote this is from your code, but does the “choose the row…” line in your code really end with a period? It should be a semicolon; “flag entry” won’t make sense (I think) unless you’ve already chosen a row in a table during that rule, but the period ends the rule, so the line with “flag entry” isn’t talking to the line where you choose the row.

You’re right, that doesn’t make sense. I changed it to a period because Inform seems kind of flaky where semi-colons and periods are concerned. Even though I know that a period ends the rule and Inform knows that a period ends the rule, for some reason it doesn’t always work out that way for me. Again, it’s probably… just me.

I changed it to a period because of the following error, which may shed some light on the matter:

Problem. In the sentence 'Choose the row with an event of wateron in the Table of Flags'  , I was expecting to read a value, but instead found some text that I couldn't understand - 'wateron'.

I was trying to match one of these phrases:

1. choose a/the/-- row with (an event - table column) of (wateron - value) in/from (table of flags - table name) 

2. choose a/the/-- row (with an event of wateron - number) in/from (table of flags - table name) 

This was what I found out:

an event = a texts valued table column

wateron = something unrecognised

Table of Flags = a table name

with an event of wateron = something unrecognised

Also if I remove the quotes around “wateron” in the table, as I’ve seen in several examples, Inform complains that it doesn’t know what the heck I’m talking about.

Let’s do this. (pseudo-code)

Instead of turning on the water:
     Choose the row with an event of showeron in the Table of Flags;
     If the flag entry is 0:
          Say "You turn on the water."
          Now the flag entry is 1;
          Continue the action.
     If the flag entry is 1:
          Say "The water is already on."

Inform hates that and whispers misogynistic things about my mother in my ear while I’m sleeping. It’s caused untold stress during family holiday gatherings.

(That second if doesn’t even have to be there, by the way. I added it for flair… I think. Inform never gets past the choosing of the row.)

Have you defined wateron, showeron, etc. as events? It seems to me that you need to do that somewhere. (Not sure what the best way to do that is – something like “An event is a kind of value. The events are wateron, showeron, etc.”?)

I could be off base about that, but the “some text I couldn’t understand” error reads like what happens when Inform expects you to have defined “wateron” and you haven’t.

…oh hey, if you’ve listed “wateron” inside quotes as your table, Inform probably is interpreting that column as having entries of the kind indexed text (or maybe just text). So maybe you need to say

an event of "wateron"

with the quotes, whenever you want to look it up.

Not sure… As far as I know, I have a table called Table of Flags. In that table, there are two columns. One is called “event” and the other is called “flag”. I would expect that if I tell Inform to look at the “event” column for the one called “wateron” and then check the “flag” column for a 0 or a 1, it would respond appropriately…?

I have a feeling you’re where I was at a few months ago. While learning inform, I hit error after exasperating compilation error to do with punctuation. The periods, semicolons, the ‘colon and indentation syntax’ versus ‘begin and end’ syntax. The good news is, once this part clicks, it stops being a problem. Then it only becomes a syntax problem, rather than a boggling-me-every-time-it-happens problem.

Another trick is, even though inform gives long feedback on errors, you start to also recognise exactly what each error means without reading past the first line. Well, at least that eventually happened for me, so I wish it for you!

So I’m about to post a version of your demo that works, and I’ll point out the errors I bumped into as I tweaked it.

Oh, and here’s a new brand of loveliness. This is the thing about Inform that infuriates me more than anything else.

This code:

Generates this error:

You wrote 'If the flag entry is 0'  : but the punctuation here ':' makes me think this should be a definition of a phrase and it doesn't begin as it should, with either 'To' 

But this code:

		Instead of turning on the water:
			Choose the row with an event of "wateron" in the Table of Flags;
			If the flag entry is 0:
				Say "You turn on the water."

Gives this error…

The phrase or rule definition 'Instead of turning on the water' is written using the 'colon and indentation' syntax for its... 

Then proceeds to complain about tabs.

I want inform to worry about my code, not my spacing. I think that’s why I had changed it from a semi-colon to a period initially. Inform should care about structure, not white space. Changing the punctuation seems to make it forget about tabs and spaces. (Which seems hypocritical, in my opinion.)

Okay - there were a lot of small syntax problems in your demo. Once I fixed those, I hit a bunch of mechanical problems to do with Inform’s stock ideas about turning things on.

In a sense, the way you’re interacting with the objects in your code at the moment is that… water is a thing which can be turned on and off. But to Inform’s eyes, that makes the water almost like a device with an on and off button. What’s more likely to make sense is that there’s a tap or shower, with a tap that you can turn to start the water. Since the tap/shower is the physical thing, my approach would be to install that, set up commands which toggle the water’s status when the tap is turned, and then reroute ‘turn water on’ to those tap turning commands as a synonym.

But first, I have fixed up the demo doing it your way (water is a device that can be turned on), just so you can see how I tweaked it.

This was your table:

Table of Flags event flag "showeron" 0

It’s fine.

Now your code:

Instead of turning on the water: Choose the row with an event of showeron in the Table of Flags; If the flag entry is 0: Say "You turn on the water." Now the flag entry is 1; Continue the action. If the flag entry is 1: Say "The water is already on."

First problem - when you say ‘row with an event of showeron’… because you have not put inverted commas around ‘showeron’, Inform is looking for a variable somewhere out there called showeron, which doesn’t exist. What you’re really trying to match is a piece of text which says “showeron”. The inverted commas always tells inform something is text. So to fix this line…

Choose the row with an event of "showeron" in the Table of Flags;

Next problem - immediately after “You turn on the water.” there needs to be a semicolon. 99% of the time, all lines that contain code have to end with a semicolon if the next line is more code (main exception - when the present line ended with a colon). Only when a section of code is completely finished and the next line is blank, that’s when you use a period.

So this line becomes:

	Say "You turn on the water.";

Next prob: ‘continue the action’ is probably not what you want here. Overall in this demo, you’re saying ‘instead of doing what inform would normally do to turn on this water thing, do the code I wrote here.’ But then at the end of it, when you say ‘continue the action’, you’re saying to Inform, ‘now stop doing it my way, and finish off the processing in your usual way’ - which will result in Inform going to the report rulebooks and such.

You did want to stop doing it your way (to prevent the ‘The water is already on.’ message appearing as well), but you don’t want Inform reporting on the action, because you just did that yourself. Using ‘continue the action’ here essentially makes Inform print both “You turn on the water”, and then its own default message about turning stuff on.

So you want something that stops your action continuing and stops Inform doing any default stuff afterwards, either. That something is probably ‘rule succeeds’. Alternatives are ‘stop the action’ and ‘rule fails’. All 3 will cause the stop, but which one you pick determines the success status for this action. Just being logical, we did turn on the water, so ‘rule succeeds’ seems like the best bet.

And again - after ‘continue the action’, you used a period when a semicolon is needed, so we’re replacing that line with ‘rule succeeds;’


Those were the syntax problems. Having dealt with those, it turns out that Inform can’t just turn anything on. In Inform’s default setup, “turn on” leads to the action “switching on” (I found this by typing ‘actions’ and ‘rules’ to monitor what verbs were going where in the demo, then typing ‘turn on water’) Inform has a kind of thing which can be switched on, which is called a device. So if we said:

the water is a device in Bathroom

That would get us in the ballpark. But I was still having trouble intercepting the action, setting up the water, etc. (I’m inexperienced with devices.) Plus I didn’t like the messages.

So I decided, ‘okay, I’m going to take over the verb ‘turn’ so it does what I want.’

I zapped Inform’s definition of ‘turn’, made a new action called ‘turning on’ that can apply to anything in my demo, and that solved the problem. This would not make much sense in the long run (being able to turn on anything, let alone water) but I did it for the sake of getting the demo running along the lines you originally stated.

Here’s the final product, which works:

[code]“Water On”

Bathroom is a room.

water is a thing in Bathroom. “There’s a shower here.”

Table of Flags
event flag
“showeron” 0

Understand the command “turn” as something new.
turning on is an action applying to one thing.
Understand “turn on [something]” as turning on.

Instead of turning on water:
Choose the row with an event of “showeron” in the Table of Flags;
If the flag entry is 0:
Say “You turn on the water.”;
now the flag entry is 1;
rule succeeds;
If the flag entry is 1:
Say “The water is already on.”

test me with “turn on water / again”.[/code]

Edit - note, I still had ‘water is a device’ when I first posted this. That is unnecessary. I changed it to ‘water is a thing in bathroom’.

As you can see, the stuff after ‘instead of turning water on’ is barely different from what you originally typed - it’s just those syntax issues that righted it. Two semicolons, a pair of inverted commas, and one line changed.

Phenomenal explanation sir. (Ma’am?) I’ll see what I can do to plug this in tomorrow and report back the results. I obviously don’t want to override the entire “turn” rule, so we’ll see what happens.

Insofar as “continue the action” is concerned, I was copy/pasting that from existing examples without understanding what it meant or what it did.

I do appreciate all the time you spent typing all this out.

Cool. It is indeed sir :wink:

  • Wade

Just FYI, you can make an object respond to the built-in switching verb by giving it the appropriate properties, e.g.:

The water can be switched on or switched off.

–Erik

You’re right, of course, Mr. Temple. I would just like to get this whole table of flags thing down for things that aren’t on or off.