Reading - to yourself, or aloud, or aloud to someone


(Mage of Maple) #1

Hello,

Ok, I’m off and running and after a couple days, I’m already pretty pleased with my progress. I am attempting something fairly complex, though, and while I’ve got it almost solved, I’m hoping it can be better still.

It involves a new action ‘reading’ (which is no longer the same as examining.) Essentially, the game contains magic scrolls. If the player just says ‘read scroll’, I want it give a general description. In this case, he is reading it to himself, not out loud, so the spell is not actually cast. Whereas ‘read scroll aloud’ should read it out loud and results in the spell being cast (making him invisible, for example.) And, to make it even more complicated, you should be able to read it to someone and the spell targets them. ‘read scroll to the druid’ should read it out loud targetting the druid - making him invisible - instead of the reader. Needless to say, this is pretty complicated…

The first problem is that reading is already a synonym for examining. I solved that with:

Understand the command "read" as something new.

The second problem is separating reading silently to one’s self to reading aloud. I basically solved this by creating two different actions and using “Understand” commands to distinguish:

[code]Reading silently is an action applying to one thing and requiring light.
Understand “read [something]” as reading silently.

Reading aloud it to is an action applying to two things and requiring light.
Understand “read [something] to [something]” as reading aloud it to.[/code]

This got the job done and makes sense to me (as in, it doesn’t seem too kludgy.) But then there’s the final problem. Reading something aloud without a target. It seems an action either applies to one thing or two things and can’t be both. So I solved this with the “rule for supplying a missing second noun” trick:

Understand "read [something] aloud" as reading aloud it. Understand "read [something] out loud" as reading aloud it. Rule for supplying a missing second noun while reading aloud (this is the reading aloud to myself rule): now the second noun is the player.

Victory! Well, almost … If I understand what I’ve read correctly, (and I haven’t tested it yet), there is still one problem. Reading aloud without a target will always target the player. But what if the player isn’t the one doing the reading? “Druid, read the scroll aloud” will result in the druid reading it out loud, but it won’t turn him invisible, as it should, it will still turn me invisible. I thought the solution to that was simply to set the second noun to “actor” rather than “player” but that does not compile, and it seems that it should.

So, does anyone know how to solve this problem so it works generically? I do have an idea, but it would be an ugly kludge. Basically, instead of setting the second noun to the player, set it to some special object the player can never find out about and then have the various rules that carry out spellcasting check for this and handle correctly. I’m hoping there’s a cleaner way.

Also, if there is a better approach to this whole reading thing, that would also be good to know :slight_smile:


#2

I’d create two separate actions, say “reading aloud” applying to one thing, and “reading it to” applying to two things. Then I’d write an instead rule redirecting “reading aloud” to “reading it to”, with the actor as second noun.


(matt w) #3

Another possibility may be to use “the person asked” rather than “the actor.” “The actor” behaves weirdly sometimes–according to zarf “‘actor’ is a scoped variable of the action-processing rulebook,” which means there are contexts in which you can’t use it. Supplying a missing noun happens before action processing, I guess, so that’s why you can’t use “actor” there. (Action processing rules will be everything from “Before” to “Report.”)

“The person asked” is a way of getting to the Inform 6 “actor” variable, as zarf says there, which is global and can be used in other contexts. Also as zarf says that may not always be exactly what you want. In fact, technically the use of “the person asked” outside of cases where you’re actually asking someone to do something is undocumented, though it’s so deeply embedded in so much code (including lots of the documentation examples) that I trust it won’t be broken anytime soon. And in any case, the case you envisioned is the documented case, in which the player is asking the druid to do something, is the documented case.

HOWEVER! It is a good rule of thumb that if supplying a missing noun/second noun is not doing what you want the first time you try it, the best thing to do is what jrb suggested: make a one-noun action and redirect it to the two-noun action. “The actor” should work there, as it’d be invoked in an “Instead” rule which is an action-processing rule. So you should take jrb’s advice instead of messing with “the person asked.” I just wanted to explain the behavior, and also mention that sometimes swapping out “the actor” for “the person asked” helps.


(Mage of Maple) #4

Thank you both. This is much cleaner:

[code]Understand the command “read” as something new.

Reading silently is an action applying to one thing and requiring light.
Understand “read [something]” as reading silently.

Reading aloud is an action applying to one thing and requiring light.
Understand “read [something] aloud” as reading aloud.
Understand “read [something] out loud” as reading aloud.

Reading it to is an action applying to two things and requiring light.
Understand “read [something] to [something]” as reading it to.
[/code]

And thanks for the detailed information about actor and “the person asked” which I hadn’t seen in the documentation yet.


(matt w) #5

It’s not all there or not totally highlighted! “The person asked” comes up in §12.3 and §12.4 of Writing with Inform, where it’s specifically applied to actions the player requests of other people.

“The actor” is mentioned in §12.14:

If you look very closely at the last sentence, it will tell you that “the actor” is not a global variable but a special value that only works inside action processing rules. But I sure didn’t figure that out until it was pointed out to me.

Then the business about how you can use “the person asked” for the actor even outside persuasion contexts isn’t in the documentation. As zarf said:

[quote]
“the person asked” is the old I6 actor global variable. It more or less means “whoever is carrying out the current action or the most recent action, depending on where we are in the processing sequence.” (Which sounds unreliable, but is no worse than “noun” or “second noun”, really.)

[quote]
Which is, I guess, why it’s not documented. (Though I think it gets set early enough that you usually won’t have to worry about getting the actor of the previous action if you use it.)


(Mage of Maple) #6

Ok, sorry, one follow-up. I promise I will not to pester you all with every little thing…

Reading should only apply to things that can be read. I have been able to make this work, but only with a LOT more code than seems it should:

[code]A thing can be readable or not readable.
Things are usually not readable.

Instead of reading silently or reading aloud:
If the noun is not readable begin;
say “There is nothing written on the [noun].”;
otherwise;
continue the action;
end if.

Instead of reading something to something:
If the noun is not readable begin;
say “There is nothing written on the [noun].”;
otherwise;
continue the action;
end if.
[/code]

My attempts to limit the Instead rule to just non readable objects (“Instead of reading something not readable”) did not work however I phrased it, but maybe I didn’t get the phrasing just right? So I used the nested if-then. And I could combine reading silently and reading aloud, but I needed to repeat the whole thing for reading it two because it targets more nouns (although this makes sense.) If this code can be shortened or cleaned up, I’d appreciate the suggestion.


(matt w) #7

You can do this with a kind of action:

[code]Reading silently is perusing. Reading aloud is perusing. Reading something to something is perusing.

Instead of perusing when the noun is not readable: say “There is nothing written on [the noun].” [/code]

As it looks like you’ve discovered, I think you can only join one-noun actions to other one-noun actions with “or.”

After a little poking around I think you may have to use a “when the noun is…” clause to get the not readable condition in the rule header, even if you restrict it to one action at a time–at least, I wasn’t able to get any variation of “Instead of reading something not readable” or “Instead of reading a not readable thing” to work.


(matt w) #8

Also please do keep posting your questions! We like answering questions.


(Mage of Maple) #9

Yes, that did the trick perfectly. Thanks! I tried a lot of various structures but I guess I did not stumble upon “after … when the noun is …” This can be tricky. The fact that it looks so much like English is deceptive.

That is good to know. I’m sure I will have more :smiley:


(Mage of Maple) #10

This grouping is handy, indeed. I also have situations where I want to handle the two kinds of reading aloud, so I went with these:

Reading silently is text-inspection. Reading aloud is text-inspection. Reading something to something is text-inspection. Reading aloud is text-enunciation. Reading something to something is text-enunciation.

In case this is useful to anyone, here is the full code for reading:

Understand the command "read" as something new.

Reading silently is an action applying to one thing and requiring light.
Understand "read [something]" as reading silently.

Reading aloud is an action applying to one thing and requiring light.
Understand "read [something] aloud" as reading aloud.
Understand "read [something] out loud" as reading aloud.

Reading it to is an action applying to two things and requiring light.
Understand "read [something] to [something]" as reading it to.

Reading silently is text-inspection. Reading aloud is text-inspection. Reading something to something is text-inspection.
Reading aloud is text-enunciation. Reading something to something is text-enunciation.

A thing can be readable or not readable.
Things are usually not readable.
Instead of text-inspection when the noun is not readable, say "There is nothing written on the [noun].";