i7 : Multiple variable types for setting a state

Hi, sorry…maybe I’m just running into syntax issues, but I’m struggling with multiple uses of a a verb for two different object.

So, I have a dial and a switch.
I can TURN DIAL TO 40.
I can TURN SWITCH TO OFF

Dial can be set to 0 to 40. Switch can be set of OFF/ON/STANDBY

Code I have so far is :

[code]A minute dial has a number called a minute. The minute of the minute dial is 0. The minute dial has a number called min setting. The min setting of the minute dial is 0. The minute dial has a number called max setting. The max setting of the minute dial is 60. The description of the minute dial is “Settings are numbered between 1 and 60. The dial is set to [minute of the minute dial].”

A black_switch_setting is a kind of value. The black_switch_settings are off, on and standby.

The black switch has a black_switch_setting. The black_switch_setting of the black switch is off. The description of the black switch is “Settings are labelled off, on and standby. The black switch is currently set to [black_switch_setting of the black switch].”

Instead of turning the minute dial: say “You have to specify a number to turn it to.”
Instead of turning the black switch: say “You have to specify a setting to switch it to.”

Setting the state of it to is an action applying to one thing and one number. Understand “turn [something] to [number]” or “set [something] to [number]” or “adjust [something] to [number]” or “put [something] at [number]” or “crank [something] to [number]” or “switch [something] to [number]” as setting the state of it to.

Check setting the state of it to:
if the noun is the minute dial:
if the number understood < min setting of the minute dial:
instead say “The lowest setting is [min setting of the minute dial].”;
if the number understood > max setting of the minute dial:
instead say “Sorry, the dial can only be set from [min setting of the minute dial] to [max setting of the minute dial].”;

Carry out setting the state of it to:
if the noun is the minute dial:
now the minute of the noun is the number understood;
say “You set the minute dial to [number understood].”;

[/code]

BUT how do I make the Setting the state of it to rule accept both numbers and (in this case black switch values) other values depending on the context WITHOUT needing to differentiate between verbs (i.e. turn,crank, put for dial; set, switch for switches - bearing in mind I will have more than one switch, each with different named settings.)

Sorry to be a pain. Have looked in vain for an example of this.

Ade.

understand "off" as 0. Understand "on" as 1. perhaps.

Yay! Thanks - v. obvious - too obvious for me :slight_smile: - although it’s a bit of a lengthy process to do the check and carry out rules.

I was thinking there was a more generic approach to bring context into the rule. I’ve been writing all sorts of conditional constructs.

Thanks again.

You can define two different actions that accept the same verbs (as typed commands). So in the simple case you could probably say something like this:

[code]Setting the number of it to is an action applying to one thing and one number. Understand “set [something] to [number]” as setting the number of it to. Setting the state of it to is an action applying to one thing and one black_switch_setting. Understand “set [something] to [black_switch_setting]” as setting the state of it to.

Carry out setting the state of it to: now the black_switch_setting of the noun is the black_switch_setting understood.

[etc., including check rules and changing your rules to setting the number of it to rules][/code]

But this wouldn’t extend to lots of dials with different settings. For this it might be better to use an action on text:

Setting the state of it to is an action applying to one thing and one topic. Understand "set [something] to [text]" as setting the state of it to.

The text the player entered would be in “the topic understood.” You would then have to write rules to check whether the topic understood is a valid setting for that dial. (My approach would be to give each dial a table with the valid settings – you can do this with something like “A dial has a table name called its settings table” – that you can check against the topic understood. But this may be overly convoluted.)

This also has the bonus that it allows you to write a sensible message for the case where the player enters something that isn’t a number or a setting. If you don’t have a catchall like this then a command like “SET BLACK DIAL TO STAND-BY” with an extra hyphen will get an unhelpful error message, I think “I didn’t understand that sentence.” (If you’re going to do it this way it might be worth thinking about whether you need to have the settings for the dials be kinds of value, or whether you can just store them as text properties; having a different kind of value for the settings of every dial seems like it’d be a pain in the patoot.)

By the way you should write a check rule to cover the case where the noun isn’t a dial. As it is neither your check nor carry out rules will apply and the game will just print a command prompt without printing any text.

I haven’t tested any of this code, BTW.

Thanks Matt - will experiment with this.

There’s already a “setting it to” action that takes one object and one topic. Just add a numerical action (I called mine “setting it numerically to”) for the dial and you should be set.

Here’s an interesting thing:

[code]Understand “set [something]” or “adjust [something]” or "put [something]"or “crank [something]” or “switch [something]” or “change [something]” as turning.

Instead of turning the minute dial: say “You have to specify a number to turn it to.”[/code]

Works for everything except switch.
So :

TURN DIAL
You have to specify a number to turn it to.
CRANK DIAL
You have to specify a number to turn it to.
SWITCH DIAL
That’s not something you can switch.

However, the next bit:

Setting the state of it to is an action applying to one thing and one number. Understand "turn [something] to [number]" or "set [something] to [number]" or "adjust [something] to [number]" or "put [something] at [number]" or "crank [something] to [number]" or "switch [something] to [number]" or "change [something] to [number]" as setting the state of it to. 

Works fine with SWITCH.

Any reason?

“switch [something]” is already given a meaning by the standard rules; if you want to give it a different meaning you have to destroy the existing grammar for it with the following line:

Understand the command "switch" as something new.

This will wipe out every understand line that starts with “switch,” so if you want the others back you have to type them in – though in your case I think you probably do want to destroy all existing grammar for “switch,” as you will want commands like “switch black switch on” to redirect to your actions rather than the standard switching on action.

For reference, here is the standard grammar for “switch”:

Understand "switch [something switched on]" as switching off. Understand "switch [something]" or "switch on [something]" or "switch [something] on" as switching on. Understand "switch [something] off" or "switch off [something]" as switching off.

(“turn [something]” is also already given a meaning, but the meaning is turning, so it works the way it’s supposed to.)

Thanks Matt. I just assumed a new understanding of a verb would override an existing one as in my second example above.

In the second ones you’re creating all-new grammar lines, so there’s nothing to override (or fail to override). “Set [something] to [number]” isn’t defined by the standard rules; the one that’s defined by the standard rules is “set [something] to [text]”.

I think that this only applies when the grammar line you want is an exact match of the one that’s already defined in the Standard Rules, but don’t take my word for it. If you ever have trouble figuring out what your commands are getting parsed to, it’s a good idea to start your game, type the command “actions,” and then try the command that’s giving you trouble; it’ll show you what action the game is trying to perform.