Runtime Errors...

Yes, I have more questions…

Basically, I created an either/or property to show whether a container was opened or unopened (I was surprised this wasn’t built into Inform), so I could have different descriptions based on whether the player had opened the ‘power control’ or not (the player would know if it was safe to open depending on if they had opened it).

Here’s the code:

A container can be unopened or opened. A container is usually unopened.
Every turn:
	if a container is open:
		now the noun is opened.


The Testing Area is a room

The control panel is here. It is fixed in place. The description is "A dazzling array of buttons and levers assault your eyes, with bizarre lights and screens dotted about upon its yellow surface. However, as you have been in a Testing Area before, you understand all the functions of the various devices. There's [a list of things that are part of the control panel] attached to it, plus much more that isn't really necessary at the moment."


The power control is part of the control panel. The power control is a closed and openable container. The description of the power control is "A large box sits on the top of the Control Panel with the words 'Power Control' marked on it, and a picture of someone being zapped by lightning. [if closed]Presumably you would die if you opened it, however there is a hinge lid, so it is openable.[otherwise if the power control is opened]Despite the bizarre warning on the lid, you know it's safe to open. [end if][if open]You can see [a list of things in the power control] in the opened box.[end if]".

Inform compiles it fine, and it runs fine. Until you try to look at something that isn’t a container:

I really have no idea why this happens. I know I could set it to just check if the power control was open every turn, as that’s the only container I want to check, but it’s annoying to see that my code doesn’t work. Ah, the life of a newbie.

Any help would be appreciated.

Pe-ads

It is; see ch. 9.12. Actions as conditions. The phrase you’re looking for is “if we have opened…” Note that the “we” here means anybody in the game, including npcs. Also, it looks like your conditionals are a little out of whack. Remember you can’t use nested conditionals in regular descriptions. If you have a description that changes based on any slightly complicated logic, it’s usually best to move it into a “say” phrase (ch. 5.10. Making new substitutions). Just remember to leave an extra space at the ends of the lines to avoid a double line break:(also remember that the tabs will be screwed up in the code below, so you’ll have to fix those manually)[code]The power control is part of the control panel. The power control is a closed and openable container. The description of the power control is “[power control desc]”.

To say power control desc:
say "A large box sits on the top of the Control Panel with the words ‘Power Control’ marked on it, and a picture of someone being zapped by lightning. ";
if the power control is closed:
if we have opened the power control:
say "Despite the bizarre warning on the lid, you know it’s safe to open. ";
otherwise:
say "Presumably you would die if you opened it, however there is a hinge lid, so it is openable. ";
otherwise:
say "You can see [a list of things in the power control] in the opened box. ".
[/code]
As for this:

The reason the above doesn’t work is because “noun” is a global variable meaning the noun of the current action, not just the thing you happen to be talking about at the moment. Therefore, if on a particular turn, the player tries “examine control panel,” the every turn rule will check to see if the control panel (since it’s the current noun) is open.

Your version of the text works much better, Mike.

However, do you (or anyone else) have any idea how to implement the opened/closed thingy? I’ve just set the game to chick if the power control is opened every turn, because that’s the only container I want to check in this game, but if I wanted to use something similar in a different game, then I’d have to set every container in the game that I wanted to check on. It’s also bugging me that the code isn’t ‘perfect’. :angry:
Yes, I know I’m a bit fastidious :wink:

Pe-ads

Maybe I don’t understand you correctly. It sounds to me like you want to change the message if the container has ever been opened during the game, which my code does. Look again (with annotations):To say power control desc: say "A large box sits on the top of the Control Panel with the words 'Power Control' marked on it, and a picture of someone being zapped by lightning. "; if the power control is closed:[<-- if the box is currently closed, the next condition is checked] if we have opened the power control: [<-- if the box has EVER been opened before, this it true] say "Despite the bizarre warning on the lid, you know it's safe to open. "; otherwise:[<-- this means that the box is closed and has NEVER been opened before] say "Presumably you would die if you opened it, however there is a hinge lid, so it is openable. "; otherwise:[<-- this means the box is currently open -- no need to check if it's been open before] say "You can see [a list of things in the power control] in the opened box. ".

If you’re just using “opened” to mark whether an object has ever been opened, then as Mike pointed out, you probably don’t need to define it at all. Inform already has two syntaxes to check past conditions.

One is the one he pointed out: “if we have opened the box” will be true if the “opening” action has ever been successfully performed on the box (by any actor).

The other is “if the box has been open”, which will be true if the box has ever been open at the start of a turn (whether it was opened by the “opening” action or through some other code).

But note that the second syntax is taken more literally, and doesn’t work with variables the way you might expect: “if the noun has been open” refers to any past noun, not the object that’s currently the noun.

Finally, your code for “opened” can be made to work like so:Every turn: now every open container is opened.

@vaporware
I realised today (on the bus of all places), that I could just use the code you suggested. Also, thanks for pointing out that Inform already has ‘opened/unopened’ stuff.

Pe-ads