Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

why doesn't this code work?

57 views
Skip to first unread message

Brian

unread,
Oct 26, 2012, 5:08:21 AM10/26/12
to
I can't find any reason why this does not work

[The purpose of pressing the button is to turn the machine on or off]

Instead of pushing the button:
If X is false:
say "The machine is on";
now X is true;
otherwise
say "The machine is off";
now X is false;
End if.

The first part of the code works

Instead of pushing the button:
If X is false:
say "The machine is on";
now X is true.

But the last part of the code produces an error when it is compiled.

I have tried putting a semi comma after the word 'otherwise' but with no
luck.

Any ideas what the problem is?


--
Regards Brian

Hannes Schüller

unread,
Oct 26, 2012, 11:27:13 AM10/26/12
to
I recommend defining the machine as a "device" (see section 3.14 of the
Inform manual).

Hannes

Dannii

unread,
Oct 26, 2012, 9:08:05 PM10/26/12
to
You need a colon : after otherwise.

But as Hannes said, you should define it as a device.

Brian

unread,
Oct 27, 2012, 7:41:57 AM10/27/12
to
I tried what you and the other person suggested but it still does not work.
Here is the code.
I welcome any suggestions on getting this code to work.

A house is a room. "Inside the house is a machine".
the Well is south of the house. "To the north is an old wooden house."
A Wishing Well is in the Well. "An old brick wishing well."

A button is a thing.
A button can be on or off, a button is usually off.
A machine is in the house. "It has a red button."
A machine is a devide.
A button is on the machine. the description is "A red button is on the
machine".
X is a truth state variable.
X is false..

understand "switch" as pushing.
understand "on", "off" as button..


[ this is the code that is not working ]
[start of code]
Instead of Pushing the Button:
If X is false:
say "You switch on the machine";
now X is true;
otherwise:
say "You stop the machine";
now X is false;
end if.
[end of code]


Every turn when X is true:
say "[if the machine is visible]The machine rattles.";

[ i was experimenting. if I type 'switch on' it does not work. If I type
'switch on machine' then it works. ]
instead of switching on:
If X is false:
say "It's on";
now X is true.

instead of switching off:
now X is false;
say "It's off".

instead of switching on Wishing Well:
say "You can't do that, its not a machine".

----------------------------------------------------------------
This is the error message I got from Inform 7.

This is the report produced by Inform 7 (build 6G60) on its most recent run
through:

Problem. The rule or phrase definition 'Instead of Pushing the Button'
seems to use both ways of grouping phrases together into 'if', 'repeat' and
'while' blocks at once. Inform allows two alternative forms, but they
cannot be mixed in the same definition.
One way is to end the 'if', 'repeat' or 'while' phrases with a 'begin', and
then to match that with an 'end if' or similar. ('Otherwise' or 'otherwise
if' clauses are phrases like any other, and end with semicolons in this
case.) You use this begin/end form here, for instance - 'end if' .

The other way is to end with a colon ':' and then indent the subsequent
phrases underneath, using tabs. (Note that any 'otherwise' or 'otherwise
if' clauses also have to end with colons in this case.) You use this
indented form here - 'If X is false'



Regards Brian





--
Regards Brian

Hannes Schüller

unread,
Oct 27, 2012, 7:49:52 AM10/27/12
to
Hello Brian,

if you don't mind "the other person" answering again.

What you're doing there is much, much too complicated. First of all,
fix those typos ("devide"). Second, you don't need "X" at all, because
once the machine is a device, you can change and check its state
directly. Same thing for "A button can be on or off, a button is
usually off." - scrap that, it only makes things unnecessarily
convoluted.

Hannes

John W Kennedy

unread,
Oct 27, 2012, 11:24:00 AM10/27/12
to
The other advice is good, but as to this error -- have you tried
actually reading it? Because it's explaining at considerable length
exactly what the problem is, y'know.


--
John W Kennedy
"The poor have sometimes objected to being governed badly; the rich
have always objected to being governed at all."
-- G. K. Chesterton. "The Man Who Was Thursday"

Brian

unread,
Oct 27, 2012, 8:30:36 PM10/27/12
to
Sorry Hannes but I couldn't remember your name.

I guess I'm still thinking like the early adventure writers did where you
need to set flags to indicate that something was switched on or off. Thanks
for the advice.

--
Regards Brian

Brian

unread,
Oct 27, 2012, 8:30:37 PM10/27/12
to
Some error messages can be difficult to understand.
I tried adding a 'begin' like the error message suggested.
I'm not certain where to place the colon when it suggests ending with a
colon.

--
Regards Brian

John W Kennedy

unread,
Oct 28, 2012, 8:51:06 PM10/28/12
to
It says you have two choices: use the colon and indentation, or use
"begin" and "end if". You're mixing the two together, and it doesn't
know what to do with that.

--
John W Kennedy
"I want everybody to be smart. As smart as they can be. A world of
ignorant people is too dangerous to live in."
-- Garson Kanin. "Born Yesterday"

Brian

unread,
Oct 29, 2012, 8:08:43 PM10/29/12
to
Thanks for your help.
As I am new to writing an adventure in the Inform 7 language there are
things that I don't understand.
Looking at this code....

instead of switching on:
If X is false:
say "It's on";
now X is true;
otherwise
now X is false;
say "It's off".

Do I put the 'begin' on the next line after 'instead of switching on' or do
I put the 'begin' on the next line after 'if X is false'?
Which colon do I remove?

--
Regards Brian

Brian

unread,
Oct 30, 2012, 7:20:01 AM10/30/12
to
After doing a search on the manual and studying some examples I found a way
to make the code work.

--
Regards Brian
0 new messages