intfiction.org

The Interactive Fiction Community Forum
It is currently Sat Feb 23, 2019 4:56 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Tue Feb 12, 2019 4:51 pm 
Offline

Joined: Sat Jul 30, 2011 2:53 pm
Posts: 38
I was experimenting with one of the excellent examples (Witnessed 1 -- §9.5) as one does, trying to add code to automatically open the battery compartment in each device -- the recorder and flashlight -- when inserting the battery into the device itself. This worked with one but not the other device, which seemed really odd.

Therefore I stripped the problem down to its basics, as one does, and still find really weird inconsistent behavior:

Code:
Test is a room.

A battery compartment is a kind of container.
A battery compartment is usually closed and openable.
One battery compartment is part of every device.

A light source is a kind of device.
The flashlight is a light source.

The cassette recorder is a device.

Understand "open [openable closed thing]" as opening.

The player carries the cassette recorder and the flashlight.

Test me with "open recorder / open flashlight".


produces this:

Code:
Test

>test me
(Testing.)

>[1] open recorder
It isn't something you can open.

>[2] open flashlight
You open the flashlight's battery compartment.


The flashlight and recorder appear to be identically created as devices, each of which has an openable battery compartment which the understand statement should open when opening the device itself. Yet only the flashlight works correctly. The Kinds Index shows both objects to be equivalently constructed. Each is a device with a battery compartment, but they behave differently.

What is going on?

I'm just as interested in tips as to how to figure out such issues as I am in a solution to this particular question.

Many thanks in advance!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Feb 12, 2019 5:46 pm 
Offline

Joined: Tue Dec 29, 2009 3:50 pm
Posts: 60
Code:
Test

>test me
(Testing.)

>[1] open recorder
It isn't something you can open.

>[2] open flashlight
You open the flashlight's battery compartment.

>open cassette
You open the cassette recorder's battery compartment.

>


Err...what?


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Feb 12, 2019 7:47 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5921
The command "open recorder" doesn't work because the recorder isn't openable. The openable object is the "recorder's battery compartment". So you could say "open recorder's compartment", or just "open recorder's".

The command "open flashlight" happens to word because Inform's word recognition stops at nine characters! So "flashlight" and "flashlight's" look like the same word to the parser.

Even though it more or less works for the flashlight, it's not an ideal situation. You have two objects with very similar names ("flashlight" and "flashlight('s) battery compartment"). Any given command like "open", "turn on", "put battery in..." has to be applied to the right one, and that's hard to arrange in a way which is transparent to the player. It's a parser fail waiting to happen.

It would be better to model each device as a single object. This is also kind of a nuisance, since Inform doesn't like the idea of something which is both a container and a device. But you can hack it together, and it will be more reliable in play.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Feb 13, 2019 11:23 am 
Offline

Joined: Sat Jul 30, 2011 2:53 pm
Posts: 38
Many thanks, Zarf! So it was primarily a naming issue and the nine character word recognition limitation. Didn't know about that. That explains why the understand statement worked for the flashlight but not the recorder.

And thanks for the pointer about how to model the objects!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Feb 15, 2019 12:15 pm 
Offline

Joined: Tue Dec 29, 2009 3:50 pm
Posts: 60
zarf wrote:
The command "open recorder" doesn't work because the recorder isn't openable. The openable object is the "recorder's battery compartment". So you could say "open recorder's compartment", or just "open recorder's".

The command "open flashlight" happens to word because Inform's word recognition stops at nine characters! So "flashlight" and "flashlight's" look like the same word to the parser.

Even though it more or less works for the flashlight, it's not an ideal situation. You have two objects with very similar names ("flashlight" and "flashlight('s) battery compartment"). Any given command like "open", "turn on", "put battery in..." has to be applied to the right one, and that's hard to arrange in a way which is transparent to the player. It's a parser fail waiting to happen.

It would be better to model each device as a single object. This is also kind of a nuisance, since Inform doesn't like the idea of something which is both a container and a device. But you can hack it together, and it will be more reliable in play.


But why did "open cassette" work to open the cassette recorder's battery compartment?

Would you be kind enough to expound on "hack it together" into a thing that is both container and device? Or point us in the right direction? Cheers :)


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Feb 15, 2019 12:23 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5568
Location: Burlington, VT
RedOrZed wrote:
zarf wrote:
The command "open recorder" doesn't work because the recorder isn't openable. The openable object is the "recorder's battery compartment". So you could say "open recorder's compartment", or just "open recorder's".

The command "open flashlight" happens to word because Inform's word recognition stops at nine characters! So "flashlight" and "flashlight's" look like the same word to the parser.

Even though it more or less works for the flashlight, it's not an ideal situation. You have two objects with very similar names ("flashlight" and "flashlight('s) battery compartment"). Any given command like "open", "turn on", "put battery in..." has to be applied to the right one, and that's hard to arrange in a way which is transparent to the player. It's a parser fail waiting to happen.

It would be better to model each device as a single object. This is also kind of a nuisance, since Inform doesn't like the idea of something which is both a container and a device. But you can hack it together, and it will be more reliable in play.


But why did "open cassette" work to open the cassette recorder's battery compartment?


In assemblies like this that have been created by a line like "One foo is part of every bar," when you create a bar named baz, Inform usually names the automatically created thing "baz's foo." So here Inform generates the name of the object as "cassette recorder's battery compartment." Then--as usual with names--each individual word can be understood as the name of the thing. So "cassette," "battery," and "compartment" all work, but the other word is "recorder's" rather than "recorder."


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Feb 15, 2019 1:23 pm 
Offline

Joined: Tue Dec 29, 2009 3:50 pm
Posts: 60
Thanks matt w, interesting answer, hopefully will stop me falling in similar traps.

(It totally won't, but we can hope :) )

[edit] So, you're saying Inform automatically disambiguated "cassette" (a non openable thing, but 8 characters) into "cassette recorder's battery compartment" but wouldn't do the same for "recorder"?

Nope, I'm still confused :(


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Feb 15, 2019 1:33 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5921
[quote]So, you're saying Inform automatically disambiguated "cassette" (a non openable thing, but 8 characters) into "cassette recorder's battery compartment" but wouldn't do the same for "recorder"?
[quote]

Correct.

It's pretty simple underneath -- it looks at a list of words and sees what matches. The list of words for this object is "cassette", "recorder's", "battery" "compartment". If the player types CASSETTE, that's in the list. RECORDER is not in the list, but RECORDER'S is. COMPARTMEZZLE counts as in the list because the parser is only looking at the first nine characters.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Feb 15, 2019 1:41 pm 
Offline

Joined: Tue Dec 29, 2009 3:50 pm
Posts: 60
zarf wrote:
Quote:
So, you're saying Inform automatically disambiguated "cassette" (a non openable thing, but 8 characters) into "cassette recorder's battery compartment" but wouldn't do the same for "recorder"?
Quote:

Correct.

It's pretty simple underneath -- it looks at a list of words and sees what matches. The list of words for this object is "cassette", "recorder's", "battery" "compartment". If the player types CASSETTE, that's in the list. RECORDER is not in the list, but RECORDER'S is. COMPARTMEZZLE counts as in the list because the parser is only looking at the first nine characters.


So Inform thinks:

"you want to open something, I have two things with the same name(the same word in both lists), lets pick the openable one and see if that works?"


Top
 Profile Send private message  
Reply with quote  
PostPosted: Fri Feb 15, 2019 3:08 pm 
Offline
User avatar

Joined: Thu Aug 22, 2013 2:48 pm
Posts: 145
I think there's another subtlety worth mentioning here. But I'm no expert on I7 internals, so Zarf, please correct me if this is wrong:

On the Z-machine, words are truncated to nine characters, but non-letters occupy more than one character slot. The word “recorder'” (nine characters including the final apostrophe) would require ten character slots, because the apostrophe isn't a letter of the alphabet. Thus, what really happens is that “recorder's” gets truncated to “recorder”, which does match the input. So in this case, I think we would get different behaviour depending on whether we're compiling for the Z-machine or Glulx, and I draw the conclusion that the original example was compiled for Glulx.

_________________
Dialog. Tethered.


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Baidu [Spider] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group