How to tell compiler something is text and not a topic

I’m wondering if there is a way to do this without an auxiliary variable.

I have an action:

Speaking it to is an action applying to one text and one thing. 

and then later:

    let S be "Good work, Margaret.";
    try Klimp speaking S to Margaret instead;

I’m using text instead of topic to preserve case. I found the inform compiler won’t allow me to specify the text directly, like:

    try Klimp speaking "Good work, Margaret" to Margaret instead;

which is why I use the variable S above.

I’m wondering if there is any to specify inline that double-quoted characters are text and not a topic?

2 Likes

You can define a phrase to make a fake conversion:

To decide which text is (T - text) as text: (- {T} -) 
	
When play begins:
	try Klimp speaking "Good work, Margaret." as text to Margaret;

Of course, you can write the phrase differently:

To decide which text is inline (T - text): (- {T} -) 

And have : try Klimp speaking inline "Good work, Margaret." to Margaret;

2 Likes

Thanks! That’s beautiful. Embedding Inform 6 code remains deep magic to me.

I notice now, though, that for some reason actions with texts instead of topics do not work in tables:

Table of Scripting Finding the Code
time        act
1 minutes	Klimp going west
1 minutes	Moira going west
1 minutes	Klimp speaking "Glad that's over." as text to Moira
1 minutes	Moira speaking "No doubt." as text to Klimp

The first two entries parse fine, but the next two are rejected by Inform:

In 'Table of Scripting Finding the Code'  , I'm reading the text 
'Klimp speaking "Glad that's over." as text to Moira'   
in column 2 (act) of row 3, but I don't know what this means.

I’ve experimented with other actions, and the text parameter does seem to be the issue here. There is also a problem storing such an action.

Foo is an action which varies.
foo is initially Klimp speaking "Glad that's over" as text to Moira.

yields:

You wrote 'foo is initially Klimp speaking "Glad that's over" as text to Moira:
but this seems to give something a name which contains double-quoted
text, which is not allowed.

Any way around this?

1 Like

as a text is a function call. It’s dynamically computed. You can’t have dynamic things in assertions (the statements that occur outside of rules or phrases or scene beginnings/endings). x is initially 1 + 1 doesn’t work either. Likewise you can’t have that kind of dynamism in defining the initial state of a table.

You could add with 20 blank rows to your table and then:

when play begins:
choose a blank row in the Table of Scripting Finding the Code;
now the time entry is 1 minutes;
now the act entry is Klimp speaking "Glad that's over." as text to Moira
[etc.]

But I wonder whether you might be struggling because you’re avoidably swimming against I7’s currents.
understand "speak [text] to [person] as speaking it to". doesn’t compile in combination with that action definition so I know there isn’t an intent for the player to ever speak. So I wonder whether it really has to be an action at all.

Or if you keep it an action, you could make it a kind of thing with their own names you can identify them by so you don’t have to worry about where I7 does or doesn’t want a double-quoted string.

an utterance is a kind of thing.
an utterance has a text called the speech.
Speaking it to is an action applying to one visible thing and one thing.
carry out an actor speaking something (called the quip) to someone (called the audience): say "[Actor] [say] '[speech of the quip]' to [audience].".
Understand the speech property as describing utterance.

understand "speak [any utterance] to [person]" as speaking it to.
gmm is an utterance. The speech of gmm is "Good morning Margaret.".
nd is an utterance. The speech of nd is "No doubt.".

Table of Scripting Finding the Code
action-duration (time)  actors-action (action)
1 minutes   Klimp going west
1 minutes   Moira going west
1 minutes   Klimp speaking gmm to margaret
1 minutes   Moira speaking nd to Klimp

what are you really trying to accomplish? Are different instances of speaking ever going to take different amounts of time? Do you really need an action column in that table, or could it be just an action name column?

2 Likes

I was overcomplicating it. You could just let 'em be topics.


Speaking it to is an action applying to one topic and one thing.
carry out an actor speaking a topic to someone (called the audience):
repeat through the table of quips begin;
  if the topic understood matches the quip-topic entry begin;
    say "[Actor] [say] '[the quip entry]' to [audience].";
    break;
  end if;
end repeat;

Table of Quips
quip (text) quip-topic (topic)
"Good morning Margaret."    "good morning margaret"
"No Doubt." "no doubt"

Table of Scripting Finding the Code
action-duration (time)  actors-action (action)
1 minutes      Klimp going west
1 minutes      Moira going west
1 minutes      Klimp speaking "good morning margaret" to margaret
1 minutes      Moira speaking "no doubt" to Klimp
2 Likes

Understood regarding the function call. That makes sense.

I was trying to adapt all the nice machinery for user actions to NPCs. So for instance, I could have something like:

Carry out Klimp speaking a text to someone during Some Scene while Klimp is angry:
    Say "Klimp scowls. [the text] Then he crosses his arms and spits.";

It doesn’t seem to be panning out, though. I ran into more problems with text as parameters to actions, which led to runtime errors. So I’m going to step back and reconsider the use of actions for speech altogether.

Thanks for your help!

2 Likes

In that specific case, I6 was not strictly necessary. You could have the same result with I7:

To decide which text is (T - text) as text: decide on T.

The downside is that the generated code is less efficient. It makes several unnecessary copies of the text string and extra function calls whereas the I6 version results in minimal code.
That’s clearly premature optimisation on my part.

2 Likes